How to set web3 solidity variable value

0 votes

This is my code: https://gist.github.com/tlatkdgus1/4885faa14ca123024fbb3fd194404352

This is the result:  https://gist.github.com/tlatkdgus1/e87c7f247fb3d0376613d25e8286ec80

Geth: https://gist.github.com/tlatkdgus1/5939f90a7b5c478f78c8ec0ecca45b5b

Sorry, I can't use stackoverflow well so upload source in Gist

I think this part is problem but i have no idea.

while w3.eth.getTransactionReceipt(tx_hash) is None:
    print (w3.eth.getTransactionReceipt(tx_hash))

Reference https://github.com/pipermerriam/web3.py

Jul 6, 2018 in Blockchain by sabby
• 4,390 points
1,878 views

1 answer to this question.

0 votes

The setLog transaction has not yet been mined by the time the the getLog call is made.

I've cleaned up your code a bit for readability, and turned your while loop into a function with a timeout. Ive also taken the liberty of making updates to use the web3.py v4 pre-release.

the web3.py pre-release (allong with eth_tester) can be installed with:

$ pip install --pre web3[tester]

import json
import time
from web3 import Web3
from web3.providers.eth_tester import EthereumTesterProvider
from solc import compile_source
from web3.contract import ConciseContract
import time

contract_source_code = '''
pragma solidity ^0.4.11;

contract contract_log {
string name;
string time;
string product;

function contract_log(){
    name='kk';
    }
function setLog(string a, string b, string c) public {
    name = a;
    time = b;
    product = c;
    }


function getLog() constant returns (string, string, string) {
    return (name, time, product);
}

}
'''

def wait_on_tx_receipt(tx_hash):
    start_time = time.time()
    while True:
        if start_time + 60 < time.time():
            raise TimeoutError("Timeout occurred waiting for tx receipt")
        if w3.eth.getTransactionReceipt(tx_hash):
            return w3.eth.getTransactionReceipt(tx_hash)


compiled_sol = compile_source(contract_source_code) # Compiled source code
contract_interface = compiled_sol['<stdin>:contract_log']

w3 = Web3(EthereumTesterProvider())

contract = w3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])

deploy_tx_hash = contract.deploy(transaction={'from': w3.eth.coinbase, 'gas':500000})
contract_address = wait_on_tx_receipt(deploy_tx_hash).contractAddress
contract_instance = w3.eth.contract(abi=contract_interface['abi'], address=contract_address)

tx_hash = contract_instance.functions.setLog(
    'tlatk',
    '12',
    'product').transact({'from':w3.eth.coinbase,'gas':500000})

wait_on_tx_receipt(tx_hash)

print(contract_instance.functions.getLog().call())
answered Jul 6, 2018 by Christine
• 15,790 points

Related Questions In Blockchain

0 votes
1 answer

How to get return value from solidity contract?

Once you call a constant function, you ...READ MORE

answered Aug 16, 2018 in Blockchain by slayer
• 29,350 points
4,757 views
0 votes
1 answer

How to set token price in solidity?

We know that 1 Ether = 1018 wei, ...READ MORE

answered Sep 25, 2018 in Blockchain by slayer
• 29,350 points
8,253 views
0 votes
1 answer

How to get value from solidity contract using java?

web3j caters for this very use case. It ...READ MORE

answered Sep 28, 2018 in Blockchain by slayer
• 29,350 points
1,743 views
0 votes
1 answer

Solidity: How to return id from hash value?

You can do it by storing the hash ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 69,210 points
2,068 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,691 views
+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,232 views
0 votes
1 answer
+1 vote
2 answers

How to convert INT to STRING in Solidity?

Look at the following code : function uintToString(uint ...READ MORE

answered Jun 27, 2018 in Blockchain by Christine
• 15,790 points
11,688 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP