0
votes

This seems like a very small problem and I am new to contract development.

I have a function in contract prototype as follows:

function exampleContractFunction(
    address somecontractaddress,
    bytes4 someCurrencySymbol,
    uint[] memory someDetails,
    uint16 someTime,
    uint8 data1,
    bytes32 data2,
    bytes32 data3
);

I am using ethers library version ^4.0.33 and truffle

On contract compilation following interface is generated.

exampleContractFunction: TypedFunctionDescription<{
      encode([
        somecontractaddress,
        someCurrencySymbol,
        someDetails,
        someTime,
        data1,
        data2,
        data3
      ]: [
        string,
        Arrayish,
        BigNumberish[],
        BigNumberish,
        BigNumberish,
        Arrayish,
        Arrayish
      ]): string;
    }>;

I try to call this for getting encoded data for contract interaction transaction that needs signing. When i call this and pass

const hexCurrency = (web3.utils.toHex('DAI'));

as someCurrencySymbol in the following call:

const data = this.contracts.somecontract.interface.functions.exampleContractFunction.encode([
      somecontractaddress, // Can be compound or dydx at the moment
      hexCurrency,
      someDetails,
      someTime,
      data1,
      data2,
      data3,
    ]);

I get this error with variation of whatever currencySymbol i pass

Error: invalid input argument (arg="someCurrencySymbol", reason="invalid bytes4 value", value="0x444149", version=4.0.42)
    at Object.throwError (/packages/types/node_modules/ethers/errors.js:76:17)

How can I send this bytes4 argument a currencySymbol?

1

1 Answers

0
votes

Have you tried with just:

web3.utils.toHex('DA')

Seems to me you're not passing just 4 bytes, indeed the value you're getting of value="0x444149" it's actually made of 6.