0

I'm trying to deploy smartcontract with web3.py. below is my simple smart contract:

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;
  }
}

below is my web3.py code

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']

when I tried this, I am getting error

TypeError: deploy() got multiple values for argument 'transaction'

so please let me know how to pass constructor argument to deploy function

2

The arguments should be passed in an array, so just change K to [K].

In addition, I recommend that you either specify all the argument names, or you specify none of them, in which case, their order is important:

  • contract.deploy(args=[K],transaction={...}) # order is not important
  • contract.deploy({...},[K]) # order is important

See the official documentation for this function here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.