Skip to content

Instantly share code, notes, and snippets.

@iivvoo
Created July 11, 2016 14:38
Show Gist options
  • Save iivvoo/53f7242808f59bb5225e8807cbe12aab to your computer and use it in GitHub Desktop.
Save iivvoo/53f7242808f59bb5225e8807cbe12aab to your computer and use it in GitHub Desktop.
import time
import pprint
from empyrean.api import IPCAPI
from keys import address, passphrase
api = IPCAPI("/home/ivo/.ethereum/geth.ipc")
res = api.personal.unlockAccount(address, passphrase)
print(api.eth.coinbase())
#code = open("example.sol", "r").read()
#compiled = api.eth.compileSolidity(code)
# print("Compiled")
# pprint.pprint(compiled)
data = "6060604052610282806100126000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806375d74f3914610044578063e7aab290146100bf57610042565b005b6100516004805050610115565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156100b15780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101136004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509090919050506101d1565b005b602060405190810160405280600081526020015060006000508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101c25780601f10610197576101008083540402835291602001916101c2565b820191906000526020600020905b8154815290600101906020018083116101a557829003601f168201915b505050505090506101ce565b90565b8060006000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061022057805160ff1916838001178555610251565b82800160010185558215610251579182015b82811115610250578251826000505591602001919060010190610232565b5b50905061027c919061025e565b80821115610278576000818150600090555060010161025e565b5090565b50505b5056"
txhash = api.eth.sendTransaction(address, gas=300000, data=data)
# print(txhash)
def wait_for_receipt(txhash):
for i in range(100):
receipt = api.eth.getTransactionReceipt(txhash)
if receipt is None:
print(".", end="", flush=True)
time.sleep(1)
continue
print(receipt)
break
return receipt
contract_receipt = wait_for_receipt(txhash)
contract_address = contract_receipt['contractAddress']
print("contract address", contract_address)
# contract_address = "0xa404a287753153946deded7caadd25d6d71ffd17"
from empyrean.abi import tohex, enc_method, enc_string
call_set_s = '0x' + tohex(enc_method("set_s(string)") +
enc_string("Hello, world")).decode('ascii')
# should be:
# call_set_s = "0xe7aab2900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c48656c6c6f2c20776f726c640000000000000000000000000000000000000000"
print("call_set_s", call_set_s)
call1 = api.eth.sendTransaction(address, to=contract_address, data=call_set_s,
gas=300000)
call1_receipt = wait_for_receipt(call1)
# should be 75d74f39
call_get_s = '0x' + tohex(enc_method("get_s()")).decode('ascii')
print("call_get_s", call_get_s)
call2 = api.eth.call(address, to=contract_address, data=call_get_s,
gas=100000)
print("call2", call2)
# call2_receipt = wait_for_receipt(call2)
# code = api.eth.getCode(contract_address)
# print(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment