Python Web3与智能合约的互动
我正在使用web3.py进行智能合同方法。尽管已成功广播,但Etherscan认为它是“ ETH”转移而不是智能合同互动。
预期的方法是Mint()。
请在下面找到我的代码:
infura_url = "https://rinkeby.infura.io/v3/<Infura code here>"
w3 = Web3(Web3.HTTPProvider(infura_url))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
address = w3.toChecksumAddress(<My wallet address>)
abi = json.loads(<ABI here>)
contract=w3.eth.contract(address=address, abi=abi)
mint_tx = contract.functions.mint(address,1).buildTransaction()
mint_tx['nonce'] = w3.eth.getTransactionCount(address)
signed_txn = w3.eth.account.sign_transaction(mint_tx, private_key=os.environ['private_key'])
txhash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
print(f'Transaction hash: {txhash.hex()}')
应该像下面的(手动完成etherscan):
https://rinkeby.etherscan.io/tx/0xf6626aa3bbfeb67f3798ad1145ec899999995b0b0b9315e8888888cbf9b9b915f915f4610b4610b4610b8872 b8872
任何帮助将不胜感激。如果需要更多信息,请告诉我,谢谢!
I'm using web3.py to transact a smart contract method. Though broadcasted successfully, etherscan thinks its an "eth" transfer and not a smart contract interaction.
The method intended is mint().
Please find my code below:
infura_url = "https://rinkeby.infura.io/v3/<Infura code here>"
w3 = Web3(Web3.HTTPProvider(infura_url))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
address = w3.toChecksumAddress(<My wallet address>)
abi = json.loads(<ABI here>)
contract=w3.eth.contract(address=address, abi=abi)
mint_tx = contract.functions.mint(address,1).buildTransaction()
mint_tx['nonce'] = w3.eth.getTransactionCount(address)
signed_txn = w3.eth.account.sign_transaction(mint_tx, private_key=os.environ['private_key'])
txhash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
print(f'Transaction hash: {txhash.hex()}')
It should be like below (Done on etherscan manually):
https://rinkeby.etherscan.io/tx/0xf6626aa3bbfeb67f3798ad1145ec89c8995b0db9315e88cbf9b915f4610b8872
But as of now it's like below (From python):
https://rinkeby.etherscan.io/tx/0x6b43cebf69b82bcbf8cce654a24627688b4fe9ea7d43dd74b4fa4c1c1049a3c7
Am I missing a step before sending the transaction ?
Any help is greatly appreciated. If any more information is required, do let me know, thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用错误的合同地址。请注意: to:和
与(to):
eTherscan上的字段进行交互。您有
地址
是您的钱包地址。您应该有
Contract_Address ='0xEB74D88306E09A78570795D7467F7467F729FFA786651'
在您的情况下。You are using the wrong address for your contract. Notice the
To:
andInteracted With (To):
fields on etherscan.You have
where
address
is your wallet address.You should have
where
contract_address = '0xeB74D88306e09A78570795d7467F729ffA786651'
in your case.