svanas / delphereum

web3 implementation for the Delphi programming language
Other
134 stars 50 forks source link

AbiEncode with bytes param return Wrong #29

Closed yonghumeijj closed 2 years ago

yonghumeijj commented 2 years ago

web3.eth.abi.encode('bytes',['0x0f00000002']) return 0xB963E9B4 0000000000000000000000000000000000000000000000000000000F00000002

The Right is

0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000005 0f00000002000000000000000000000000000000000000000000000000000000

From ABI Encoding Service Online for Solidity Smart Contracts by HashEx Check

yonghumeijj commented 2 years ago

web3.eth.abi.encode('bytes', [&array([$0f,$00,$00,$00,$02])]); return 0xB963E9B4 0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000005 000000000000000000000000000000000000000000000000000000000000000F 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000002

svanas commented 2 years ago

@yonghumeijj When you encode an arg that starts with 0x, Delphereum will interpret that as a number or an address. You will want to pass in a string that starts with 0b, for example: web3.utils.toBin(BigInteger.Create('0x0f00000002'))

yonghumeijj commented 2 years ago

@svanas
Thx