rust-ethereum / ethabi

Encode and decode smart contract invocations
Apache License 2.0
517 stars 186 forks source link

Invalid Data when decoding #245

Open honkler opened 3 years ago

honkler commented 3 years ago

I'm trying to decode UniswapRouter functions. Decoding the method

swapExactTokensForETH(uint256 amountIn, uint256 amountOutMin, address[] path, address to, uint256 deadline)

returns

./ethabi decode params -t '(uint256,uint256,address[],address,uint256)' 0000000000000000000000000000000000000000000000b0edf30260784f1a08000000000000000000000000000000000000000000000000264439d42c24ad2600000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000ca274cc0405bd4317adc3cd5975265be503f1ee50000000000000000000000000000000000000000000000000000017c04528c94000000000000000000000000000000000000000000000000000000000000000200000000000000000000000001c2086facfd7aa38f69a6bd8c91bef3bb5adfca000000000000000000000000b31f66aa3c1e785363f0875a1b74e27b85fd66c7 Error: Invalid data

while the same works fine using web3.js:

3263773007792569260552,2757392455294037286,[0x01C2086faCFD7aA38f69A6Bd8C91BEF3BB5adFCa,0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7],0xCA274cc0405Bd4317Adc3Cd5975265be503f1ee5,1632160091284

Other functions in the same ABI like addLiquidity return correct data. I tried leaving the mehod id in, but it makes no difference. Sorry for bad formatting.

YNX940214 commented 2 years ago

just use https://crates.io/crates/ethereum_abi , much better

kamikazebr commented 2 years ago

@honkler you need run it without tuple and individual

ethabi decode params -t 'uint256' -t 'uint256' -t 'address[]' -t 'address' -t 'uint256' 0000000000000000000000000000000000000000000000b0edf30260784f1a08000000000000000000000000000000000000000000000000264439d42c24ad2600000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000ca274cc0405bd4317adc3cd5975265be503f1ee50000000000000000000000000000000000000000000000000000017c04528c94000000000000000000000000000000000000000000000000000000000000000200000000000000000000000001c2086facfd7aa38f69a6bd8c91bef3bb5adfca000000000000000000000000b31f66aa3c1e785363f0875a1b74e27b85fd66c7

result

uint256 b0edf30260784f1a08
uint256 264439d42c24ad26
address[] [01c2086facfd7aa38f69a6bd8c91bef3bb5adfca,b31f66aa3c1e785363f0875a1b74e27b85fd66c7]
address ca274cc0405bd4317adc3cd5975265be503f1ee5
uint256 17c04528c94