Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ethers.js AbiCoder.encode bytes #3

Open
EvanHenrs opened this issue Oct 22, 2022 · 1 comment
Open

ethers.js AbiCoder.encode bytes #3

EvanHenrs opened this issue Oct 22, 2022 · 1 comment

Comments

@EvanHenrs
Copy link

AbiCoder.encode bytes 问题

var dynamicOffset_1 = dynamicWriter.length; coder.encode(dynamicWriter, value);
原本代码 没有赋值就取长度

修复代码
coder.encode(dynamicWriter, value); var dynamicOffset_1 = dynamicWriter.length;

先赋值在取长度

@EvanHenrs
Copy link
Author

EvanHenrs commented Oct 23, 2022

let signature = "0xa023966c15a4fdefac7e06c06a869f77adfc5359fe26c7241f122266b063bd280941e2f6922b42656ce53ef0d32d071ac6178c88195bc8f8c6f597792d57304c1b" let abiCoder = new ethers.utils.AbiCoder(); let signature_hex = abiCoder.encode(["bytes"], [signature]).replace("0x", ""); console.log(signature_hex)

错误输出结果:00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000041a023966c15a4fdefac7e06c06a869f77adfc5359fe26c7241f122266b063bd280941e2f6922b42656ce53ef0d32d071ac6178c88195bc8f8c6f597792d57304c1b00000000000000000000000000000000000000000000000000000000000000

正确输出结果:00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000041a023966c15a4fdefac7e06c06a869f77adfc5359fe26c7241f122266b063bd280941e2f6922b42656ce53ef0d32d071ac6178c88195bc8f8c6f597792d57304c1b00000000000000000000000000000000000000000000000000000000000000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant