繁体   English   中英

使用 swapexactethfortokens 时 Web3py 事务被还原

[英]Web3py Transaction being reverted when using swapexactethfortokens

我正在使用以下 function 发起交易。 合约 = web3.eth.contract(地址=路由器地址,abi=PancakeABI)

nonce = web3.eth.get_transaction_count(sender_address)
amountIn = (web3.toWei(0.0001,'ether')) 
start = time.time()
print(web3.toWei('0.002','ether'))
toBuyBNBAmount = web3.toWei("0.0002", 'ether')
pancakeswap2_txn = contract.functions.swapExactETHForTokens(
0, # here setup the minimum destination token you want to have, you can do some math, or you can put a 0 if you don't want to care
[spend,contract_id],
sender_address,
(int(time.time()) + 1000000)
).buildTransaction({
'from': sender_address,
'value': toBuyBNBAmount,#This is the Token(BNB) amount you want to Swap from
'gas': 160000,
'gasPrice': web3.toWei('5', 'gwei'),
'nonce': nonce
})



 
signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key=private)
tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
print(web3.toHex(tx_token))

但是每次我的交易被还原时: https://bscscan.com/tx/0x021ea258b937ba1575cdf5aed0f49fcad1143f2fc8b25eb8efffdc2347ca6729 在此处输入图像描述

我认为这个代码行是问题[spend,contract_id]你需要把[tokenA_address, tokenB_address]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM