Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ethereum.py
import json
import time
from web3 import Web3, HTTPProvider,TestRPCProvider
from solc import compile_source
from web3.contract import ConciseContract
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);
}
}
'''
compiled_sol = compile_source(contract_source_code) # Compiled source code
contract_interface = compiled_sol['<stdin>:contract_log']
provider = HTTPProvider('http://0.0.0.0:9945')
w3 = Web3(provider)
contract = w3.eth.contract(contract_interface['abi'],
bytecode=contract_interface['bin'])
tx_hash = contract.deploy(transaction={'from': w3.eth.coinbase, 'gas':50000000})
print (tx_hash)
while w3.eth.getTransactionReceipt(tx_hash) is None:
print (w3.eth.getTransactionReceipt(tx_hash))
contract_address = w3.eth.getTransactionReceipt(tx_hash).contractAddress
print (contract_address)
contract_instance = w3.eth.contract(contract_interface['abi'],
contract_address, ContractFactoryClass=ConciseContract)
print (contract_instance)
print (contract_instance.setLog('tlatk', '12', 'product',transact={'from':
w3.eth.coinbase,'gas':3000000}))
contract_instance.set(12,transact={'from': w3.eth.coinbase,'gas':3000000})
print (contract_instance.getLog())
print('Contract value: {}'.format(contract_instance.getLog()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.