[英]Web3.py : How to call token functions without source code
I created a basic MintableToken
with OpenZeppelin framework but I have lost my source code. 我用OpenZeppelin框架创建了一个基本的
MintableToken
,但是我丢失了我的源代码。 I want to mint more of my tokens and I am trying to do so through web3.py 我想要更多我的代币,我试图通过web3.py这样做
Here is my current code 这是我目前的代码
web3 = Web3(Web3.HTTPProvider("https://mainnet.infura.io/v3/MYAPI"))
web3.eth.defaultAccount = 'MYACC_ADDR'
abi = [
{
"constant": False,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_amount",
"type": "uint256"
}
],
"name": "mint",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": False,
"stateMutability": "pure",
"type": "function"
}
]
address = web3.toChecksumAddress('CONTRACT_ADDR') # FILL IN YOUR ACTUAL ADDRESS
contract = web3.eth.contract(address=address, abi=abi)
print(contract.functions.mint('MYACC_ADDR', 200).call())
Running this code via python3 mint.py
prints True
, but the contract isn't actually called. 通过
python3 mint.py
运行此代码python3 mint.py
打印True
,但实际上并未调用该契约。 Any tips? 有小费吗?
"stateMutability": "pure"
That's wrong and means that by default web3.py
will make a local call to a node instead of sending an actual transaction. 这是错误的,意味着默认情况下
web3.py
将对节点进行本地调用,而不是发送实际的事务。
I believe it should be this instead: 我相信它应该是这样的:
"stateMutability": "nonpayable"
Of course, after that change note that you'll need to provide web3.py
with a from
address and a private key to sign the transaction with. 当然,在更改之后请注意,您需要为
web3.py
提供一个from
地址和一个私钥来签署交易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.