Erc-20

如何在 Web3.py 中發送 BEP20 令牌?

  • September 6, 2021
def send_token_from_contract_in_bsc(tx_amount, tx_bsc_addr):
   web3_BSC = Web3(Web3.HTTPProvider(bscTestnet_url))
   contract_bsc_addr = web3_BSC.toChecksumAddress('0x74d4c3f8620c69C68a2144D4e1B4B7EE660cBA4D')
   bep20_addr_USDC = web3_BSC.toChecksumAddress('0x64544969ed7ebf5f083679233325356ebe738930')
   contract_bsc = web3_BSC.eth.contract(address = contract_bsc_addr, abi = contractAbi)
   bsc_Nonce = web3_BSC.eth.getTransactionCount(bscAccount)
   contract_method_transferToken = contract_bsc.functions.transferToken(bep20_addr_USDC, web3_BSC.toWei(tx_amount, 'wei'), web3_BSC.toChecksumAddress(tx_bsc_addr))
   contract_method_transferToken_build_tx = contract_method_transferToken.buildTransaction({
     'chainId': 97,
     'nonce': bsc_Nonce,
     'from': web3_BSC.toChecksumAddress(bscAccount),
     'value': web3_BSC.toWei(tx_amount, 'wei'),
     'gas': 21000,
     'gasPrice': web3_BSC.toWei('33', 'gwei'),
   })
   bsc_sign_tx_transferToken = web3_BSC.eth.account.signTransaction(contract_method_transferToken_build_tx, private_key = PRIVATE_KEY)
   bscTxHash = web3_BSC.eth.sendRawTransaction(bsc_sign_tx_transferToken.rawTransaction)

大家好!我嘗試在 BSC 中發送 BEP20 令牌,一切正常,tx 被訂閱,但沒有推送到測試網,問題出現在最後一行:

bscTxHash = web3_BSC.eth.sendRawTransaction(bsc_sign_tx_transferToken.rawTransaction)

錯誤:ValueError:{‘code’:-32000,‘message’:‘invalid sender’}

如果有人有想法,我會很高興看到:)

我解決了我的問題,問題出在bscTestnet_url錯誤的節點 url 中。

引用自:https://ethereum.stackexchange.com/questions/108163