我试图调用路由器合同的swapExactTokensForTokens,我需要将令牌a交换到令牌B。以下是交易代码:
router = '0x0000000'
abi = '[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},.... {"stateMutability":"payable","type":"receive"}]'
router_contract = w3.eth.contract(router, abi=abi)
tokenA = '0x000...'
tokenB = '0x000...'
path = [tokenA, tokenB]
txn = router_contract.functions.swapExactTokensForTokens(amount, min_amount, path, personal_wallet, (int(time()) +1000) ).buildTransaction({
'gas': 81000,
'gasPrice': w3.toWei('10', 'gwei'),
'nonce': w3.eth.get_transaction_count(personal_wallet),
})
我在事务中遇到以下错误:
更新:
当增加gas并在
buildTransaction
中添加from
字段时,上述代码可以正常工作相关问题 更多 >
编程相关推荐