【问题标题】:Web3 Signing transaction issue Non-hexadecimal digit found (Python)Web3 签名交易问题找到非十六进制数字(Python)
【发布时间】:2022-01-05 03:15:36
【问题描述】:

我正在尝试在币安智能链中完成购买代币的交易,但在签名交易部分出现错误,我无法解决。

代码:

PancakeABI = open('pancakeABI','r').read().replace('\n','')
bsc="https://bsc-dataseed.binance.org/"
web3 = Web3(Web3.HTTPProvider(bsc))
contract_id = web3.toChecksumAddress(tokaddr)

#Checking balance for test
balance = web3.eth.get_balance(sender_address)
humanReadable = web3.fromWei(balance,'ether')
print(humanReadable)

#Setup the contract
contract = web3.eth.contract(address=router_address, abi=PancakeABI)
nonce = web3.eth.get_transaction_count(sender_address)
start = time.time()
print(web3.toWei('0.02','ether'))

#Send transaction
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': web3.toWei(0.02,'ether'),#This is the Token(BNB) amount you want to Swap from
'gas': 250000,
'gasPrice': web3.toWei('5','gwei'),
'nonce': nonce,
})

#Sign Transaction
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))

这是我收到的错误:

【问题讨论】:

标签: python web3 binance-smart-chain web3py


【解决方案1】:

已解决的问题: 使用种子短语作为私钥。 实际的私钥可以这样获取:

  • 进入metamask,点击角落里的3个按钮,然后点击账号 详细信息和导出密钥。

【讨论】:

    猜你喜欢
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2019-09-07
    • 2021-08-30
    • 1970-01-01
    • 2014-05-10
    相关资源
    最近更新 更多