0

I have a method in solidity:

function getVotesWithParams(
    address account,
    uint256 blockNumber,
    bytes memory params
) public view virtual override returns (uint256) {
    return _getVotes(account, blockNumber, params);
}

It takes in a bytes params, that bytes params is suppose to represent a struct:

struct VoteOptions {
    uint24 supportOption;
    uint24 percent;
}

Type chain generates this struct to represent it:

export type VoteChoicesStruct = {
  name: PromiseOrValue<string>;
  data: PromiseOrValue<BytesLike>;
};

I'm creating that struct in a test like so:

const voteOptions: VoteOptionsStruct[] = [{ supportOption: BigNumber.from(0), percent: BigNumber.from(1000)}]
const voteData = defaultAbiCoder.encode(["bytes"], [voteOptions]);

When I try to encode it into bytes I get an error:

Error: invalid arrayify value (argument="value", value=[{"type":"BigNumber","hex":"0x00"},{"type":"BigNumber","hex":"0x03e8"}], code=INVALID_ARGUMENT, version=bytes/5.7.0)

1 Answer 1

1

hmm, turns out I shouldnt be passing bytes, it need to know the internal types in solidity.

const voteOptionsValues = voteOptions.map(o => Object.values(o));
const voteData = defaultAbiCoder.encode(["tuple(uint24,uint24)[]"], [voteOptionsValues]);

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.