我正在尝试使用web3.py部署智能合同。以下是我的简单智能合同:
pragma solidity ^0.5.0;
contract homeAutomation{
string public greeting;
constructor(string memory _greet) public {
greeting=_greet;
}
function greet(string memory _gree) public {
greeting =_gree;
}
}下面是我的web3.py代码
contract = w3.eth.contract(abi=abi, bytecode=bytecode)
K = input('write your greeting:' )
# Get transaction hash from deployed contract
tx_hash = contract.deploy(K,transaction={'from': w3.eth.accounts[0], 'gas': 410000})
# Get tx receipt to get contract address
tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
contract_address = tx_receipt['contractAddress']当我尝试这个的时候,我会犯错误。
TypeError: deploy() got multiple values for argument 'transaction'因此,请让我知道如何传递构造函数参数来部署函数。
发布于 2019-03-26 06:47:39
参数应该在数组中传递,所以只需将K更改为[K]即可。
此外,我建议您要么指定所有参数名,要么不指定任何参数名称,在这种情况下,它们的顺序非常重要:
contract.deploy(args=[K],transaction={...}) # order is not importantcontract.deploy({...},[K]) # order is important请参阅此函数这里的正式文档。
https://ethereum.stackexchange.com/questions/68846
复制相似问题