1

I'm trying to execute a swap by Onesplit contract at:

0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E

Here is my Python (web3) code:

transaction = onesplit_abi_contract.functions.swap(
            '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',  #WETH TOKEN
            '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',  #USDC TOKEN
            1000000000000000000,
            0,
            [5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, 0, 0, 0, 0, 0, 0],
            0,
            ).buildTransaction({
                'from': wallet_address,
                'nonce': w3.eth.get_transaction_count(wallet_address),
                'gas': 190000,
                'gasPrice': w3.eth.gas_price
            })
signed_trx = w3.eth.account.signTransaction(transaction, private_key)
trx_hash = w3.eth.sendRawTransaction(signed_trx.rawTransaction)

I always receive this error:

Fail with error 'SafeERC20: low-level call failed'

Same syntax using ETH instead of WETH address, adding 'value': 1000000000000000000 to buildTransaction parameters works perfectly...

transaction = onesplit_abi_contract.functions.swap(
            '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',  #ETH TOKEN
            '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',  #USDC TOKEN
            1000000000000000000,
            0,
            [100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            0,
            ).buildTransaction({
                'from': wallet_address,
                'nonce': w3.eth.get_transaction_count(wallet_address),
                'gas': 190000,
                'gasPrice': w3.eth.gas_price,
                'value': 1000000000000000000
            })
signed_trx = w3.eth.account.signTransaction(transaction, private_key)
trx_hash = w3.eth.sendRawTransaction(signed_trx.rawTransaction)

who knows what's happening? I'm confused...

0 Answers0