Almacenamiento de hash de IPFS en solidez

Estoy almacenando hash IPFS en solidez usando esta guía

https://www.reddit.com/r/ethdev/comments/6lbmhy/a_practical_guide_to_cheap_ipfs_hash_storage_in/

    const cid = "QmNXnCWPS2szLaQGVA6TFtiUAJB2YnFTJJFTXPGuc4wocQ";

    const fromIPFSHash = hash => {
        const bytes = bs58.decode(hash);
        const multiHashId = 2;
        // remove the multihash hash id
        return bytes.slice(multiHashId, bytes.length);
    };
    const toIPFSHash = 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;
    };


    it('Store encoded ', async () => {
       const bytes32 = fromIPFSHash(cid);
          const str = bytes32.toString('hex')
          console.log(str);

          await instance.setBytes.sendTransaction(str);
          const returnedBytes = await instance.getBytes.call();

          console.log(returnedBytes);
          const originalCid = toIPFSHash(returnedBytes);
          console.log(originalCid);//QmUu4JqHgHcT6Q8PxvDn1UzZq2utkgf7RfgGv4eeYZ3Lyu

          assert(originalCid == cid); // it fails
});

La afirmación anterior falla.

pragma solidity ^0.4.4;

contract Hello {
    bytes32 x;
    function getBytes() returns(bytes32){
        return x;
    }
    function setBytes(bytes32 b)  {
        x = b;
    }

}

Respuestas (1)

Intente anteponer 0xpara que web3.js sepa que el argumento debe interpretarse como hexadecimal y no como una cadena.