【问题标题】:How to transfer an ERC20 token between wallets with web3.py如何使用 web3.py 在钱包之间转移 ERC20 代币
【发布时间】:2020-10-15 08:19:07
【问题描述】:

我想知道,使用 web3.py 在两个钱包之间转移 ERC20 代币的正确方法是什么?我正在测试 Rinkeby 测试网络上的所有内容。

这是我尝试过的...

from ethtoken.abi import EIP20_ABI
from web3 import Web3

token_from = "from_address"
token_to = "to_address"
token_to_private_key = "your_private_key"

#w3 = Web3(Web3.HTTPProvider(infura_url))


contractAddress = "contract_address"
infura_url = "https://rinkeby.infura.io/v3/your_infura_key"
# Fill in your infura API key here
w3 = Web3(Web3.HTTPProvider(infura_url))

contract = w3.eth.contract(address=contractAddress, abi=EIP20_ABI)

nonce = w3.eth.getTransactionCount(token_from)  



# Build a transaction that invokes this contract's function, called transfer
token_txn = contract.functions.transfer(
     token_to,
     1,
 ).buildTransaction({
     'chainId': 1,
     'gas': 70000,
     'gasPrice': w3.toWei('1', 'gwei'),
     'nonce': nonce,
 })


signed_txn = w3.eth.account.signTransaction(token_txn, private_key=token_to_private_key)

w3.eth.sendRawTransaction(signed_txn.rawTransaction)  

当我尝试使用我的地址和私钥运行此程序时,我收到错误:ValueError: {'code': -32000, 'message': 'invalid sender'}

我该如何解决这个问题?或者......有没有更好的方法来使用 web3.py 传输 erc20 令牌?

感谢任何帮助。

谢谢

【问题讨论】:

    标签: python web3 erc20


    【解决方案1】:
    猜你喜欢
    • 2018-03-26
    • 2021-10-08
    • 2020-10-16
    • 2020-07-24
    • 2020-01-31
    • 2018-07-02
    • 1970-01-01
    • 2018-04-10
    • 2021-08-06
    相关资源
    最近更新 更多