Anyone encountered such issue in web3 py?
I’m trying to encode exactInput function but get an error
Also tried swapContract.encodeABI(fn_name='exactInput', args=args),
But still get an error
Anyone can help?

Jul 7, 2023, 7:51 AM
Jul 7, 2023, 7:51 AM
You are sending the wrong args. The function does not use a path array[ ] of address but bytes

Check the args and refactor your code

Also, it has to be passed in as a tuple
Jul 7, 2023, 11:59 AM
Could not identify the intended function with name exactInput, positional arguments with type(s) bytes,address,int,int,int and keyword arguments with type(s) {}.
Found 1 function(s) with the name exactInput: ['exactInput((bytes,address,uint256,uint256,uint256))']

i did as you said but still get this error, maybe i need to convert int to uint256? how to do that?
Jul 7, 2023, 12:21 PM
Did you pass it in as a tuple?
Jul 7, 2023, 12:26 PM
Yes tuple((arg1, arg2…)) is what I did
Jul 7, 2023, 12:26 PM
Let me see how...paste the code here
Jul 7, 2023, 12:27 PM
Jul 7, 2023, 12:28 PM
Let me see how...the tuple is supposed to have one set of parentheses not two
Plus you don't need to state the type tuple in your code
Jul 7, 2023, 12:58 PM
It won’t work with 1 parenthesis as tuple(arg1., arg2…) thinks I am passing 5 args
Even if I remove it it gives me the same error
Jul 7, 2023, 1:02 PM
your bytes [ ] array isn`t correct
Jul 7, 2023, 1:03 PM
how to encode an array to bytes?
Jul 7, 2023, 1:03 PM
use the contract.encodeABI
Jul 7, 2023, 1:04 PM
if i use web3.to_bytes([]) i get
TypeError: expected a bool, int, byte or bytearray in first arg, or keyword of hexstr or text
how will this help to encode my array, it encodes the function data doesn't it?
Jul 7, 2023, 1:05 PM
Yes...you`ll pass the function data into the multicall or just use the exactInputSingle function
I suggest you use the exactInputSingle since you are trying to swap
Jul 7, 2023, 1:06 PM
same error
Jul 7, 2023, 1:08 PM
You`ll be able to make the call without having to encode the tokenIn and tokenOut addresses in an array
Jul 7, 2023, 1:08 PM
Jul 7, 2023, 1:08 PM
You are supposed to encode the data and then pass it into the function
And its supposed to be passed into the multicall function
Jul 7, 2023, 1:10 PM
it doesn't matter what function i call, there is a write function in the router contract called exactInput
multicall will only make it harder to swap
i just need to solve this trouble of encoding the struct
Jul 7, 2023, 1:12 PM
You are supposed to encode the data and then pass it into the multicall function
I know it works just like the exactlnputSingle

You are having difficulty encoding the bytes path

Thus my suggestion
Jul 7, 2023, 1:13 PM
no i can actually send the exactInput function and it will still swap the tokens without multicall but the issue is not with multicall rather with encoding the struct
do you know how i can encode the path? convert path to bytes is the main issue i guess
Jul 7, 2023, 1:14 PM
I know... but your issue now is encoding bytes path ... right?
Jul 7, 2023, 1:14 PM
i pass b'0x' for tests, maybe there is an issue with this and if i encode and pass the actuall array that is needed it might work

also the issue might be with have int rather than uint256

these both issues i don't know how to solve
Jul 7, 2023, 1:15 PM
Python uses int as its equivalent for uint256 so that's not the issue
The issue is with the encoding...
Use this...
Jul 7, 2023, 2:01 PM
oh thx i will try it
Jul 7, 2023, 2:01 PM
Always a pleasure...
Jul 7, 2023, 2:02 PM

© 2024 Draquery.com All rights reserved.