0

I am trying to deploy my contract onto the blockchain in my private network with local private key (no wallet: I used web3.auto.w3.account.create()).

I know how to send normal transaction with local private key. But deploying contract is not easy for me. I am using web3.py

>>> from web3.auto import w3
>>> account = w3.eth.account.create()
>>> account.address
'0x653E3CE959a236278cF110E7C63052cDf94DB03B'
>>> account.privateKey
HexBytes('0x2aa62ebc701c8f075dc3755a85ddc5309025494288c408bc8e66fd095c393f91')

I get address and private key. so what I want to do is ...

web3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8555"))

contract_src = open('Funding.sol').read()
contract_bin = compile_source(contract_src)
contract_interface = contract_bin['<stdin>:Funding']

transaction = {
    'from': <public address which I got>,
    'gas': 100000,
    'gasPrice': 0,
    'nonce': 0,
    ...
}
signed = w3.eth.account.signTransaction(transaction, <private key which I got>)
web3.eth.sendRawTransaction(signed.rawTransaction)

In transaction, what information should I put in ??

My contract looks like below:

contract Information {
    String str;

    function modify(String s) public {
        str = s;
    }
}

contract Bag {
    mapping(uint256 => Bag) contents;
    uint256 public i = 0;

    function create() public {
        contents[i++] = new Information();
    }
}
0

What you are trying to do is feasible and should work. your contract doesn't really matter that much other than the arguments to end for the function you are calling.

What you put in transaction is the transaction object, you can find it here : https://web3js.readthedocs.io/en/1.0/web3-eth.html?highlight=transaction#id62

The data Attribute of the transaction object is the ABI encoded function with it's argument, you can get it via this example : https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#id31

myContract.methods.myMethod(123).encodeABI(); '0x58cf5f1000000000000000000000000000000000000000000000000000000000000007B

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.