3

I have been having this problem with the web3 library for a while now and I am not sure how to solve.

I am encoding a transaction within a react app. So far, all contract interactions inside the app with the same contract are going smoothly, this problem seems to have arisen when I am using a string as a method argument.

Here is the method I am calling in my contract:

function sendShardToShardOwner(address _shardOwner, string memory _shardURI) public onlyOwner
    {
        require(shardHolders[_shardOwner], "Not a valid Trustee");
        nftContract.distributeShard(_shardOwner, _shardURI);
    }

The contract takes two parameters as arguments, an address and an IPFS URL as a string. When calling the below method to encode the ABI, I receive the offending arrayify error.

const recoveryContract = new this.web3.eth.Contract(RecoveryContract.abi, this.recoveryContractAddress);
const data = recoveryContract.methods.sendShardToShardOwner(address, "QmbSo373odJ8HosMNYgsFGw5bfkKrG5GhkZwJX9KYNL4zu").encodeABI()

Log:

Error: invalid arrayify value (argument="value", value="516d62536f3337336f644a38486f734d4e5967734647773562666b4b72473547686b5a774a58394b594e4c347a75", code=INVALID_ARGUMENT, version=bytes/5.0.11)
    at Logger.makeError (index.ts:205)
    at Logger.throwError (index.ts:217)
    at Logger.throwArgumentError (index.ts:221)
    at arrayify (index.ts:136)
    at toUtf8Bytes (utf8.ts:242)
    at StringCoder.encode (string.ts:15)
    at array.ts:62
    at Array.forEach (<anonymous>)
    at pack (array.ts:54)
    at TupleCoder.encode (tuple.ts:23)
    at AbiCoder.encode (abi-coder.ts:106)
    at ABICoder.push../node_modules/web3-eth/node_modules/web3-eth-abi/lib/index.js.ABICoder.encodeParameters (index.js:121)
    at index.js:439
    at Array.map (<anonymous>)
    at Object._encodeMethodABI (index.js:438)
    at RecoveryContractManager.recoverPublicKeyFromUser (RecoveryContractManager.js:387)

Upon investigation, the value "516d6...a75" is the hex representation of the string I have passed as a parameter. From looking at the call stack, the error is being thrown within a web3 dependency "@ethersproject/bytes". I tried to reproduce the error in an isolated environment by encoding the transaction with identical parameters and I have had no luck reproducing it.

I am posting to see if anyone has had a similar error and if anybody has been able to fix it. So far I've tried the classics: isolating the error, downgrading my web3 a few times, redeploying my contracts, reinstalling node modules, all with no luck.

1
  • 1
    I have the same error too, but mine's in Waffle from unit testing: Error: invalid arrayify value (argument="value", value="abcdefg", code=INVALID_ARGUMENT, version=bytes/5.1.0).
    – Pottedtree
    Jul 5, 2021 at 3:57

1 Answer 1

1

Convert string to byte32:

   function web3StringToBytes32(text) {
        var result = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(text));
        while (result.length < 66) { result += '0'; }
        if (result.length !== 66) { throw new Error("invalid web3 implicit bytes32"); }
        return result;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.