簡體   English   中英

如何使用 web3.py 在錢包之間轉移 ERC20 代幣

[英]How to transfer an ERC20 token between wallets with web3.py

我想知道,使用 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 令牌?

任何幫助表示贊賞。

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM