If I have
const ENCODING = `
tuple(
address foo,
bytes4 bar
)`;
Then the following _will_ work:
new ethers.utils.Interface([ENCODING]).encode({ foo, bar });
However the following will error:
ethers.utils.defaultAbiCoder.encode([ENCODING], [{ foo, bar }]);
Like so:
unexpected character "a" at position 22 in "
tuple(
address foo,
bytes4 bar
)"
I think it is because different parsing logic is used? @ricmoo
I think this is because I don鈥檛 handle newline as whitespace... I can look into it. I can probably just replace \n with space...
Oh. Looking at the above code again, you are using Interface, which expects a function of sent signature, not a type.
In the first example it works in the first case because you are constructing a function named tuple, which takes in an address and a bytes4. It has nothing to do with an actual tuple.
I have confirmed the issue you are experiencing is the newlines. For now, if you use ENCODING.replace(/\n/g, '') it will work fine. I will look into treating those as normal whitespace for the aBI coder.
Ah, makes sense, thanks @ricmoo. It remains to be the case that it works for this, too:
new ethers.utils.Interface([`foobar(${ENCODING})`]).encode({ foo, bar });
You should be able to safely use newline (or any other whitespace) now in the human-readable ABI, in version4.0.16. Let me know if there are still problems, and feel free to re-open this issue.
Thanks! :)
Most helpful comment
You should be able to safely use newline (or any other whitespace) now in the human-readable ABI, in version
4.0.16. Let me know if there are still problems, and feel free to re-open this issue.Thanks! :)