You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @MrChico , thank you so much I'm using your code in production for Ninfa.io marketplace nft contracts, you're leet!
I'm currently using javascript for encoding ipfs CID to bytes32, do you have any pointers for doing the same in Solidity? For writing some scripts in Foundry!
For the record @hen-hao
const bs58 = require("bs58");
const getBytes32FromCID = (str) => {
// remove leading 0x
const remove0x = str.slice(2, str.length);
// add back the multihash id
const bytes = Buffer.from(`1220${remove0x}`, "hex");
const hash = bs58.encode(bytes);
return hash;
};
const getCIDFromBytes32 = (hash) => {
let bytes = bs58.decode(hash);
const multiHashId = 2;
// remove the multihash hash id
bytes = bytes.slice(multiHashId, bytes.length);
return web3.utils.bytesToHex(bytes);
};
The b58 encode function is awesome, would there be a way to make a similar one that decodes instead?
The text was updated successfully, but these errors were encountered: