Skip to content

Instantly share code, notes, and snippets.

@crypto-diaz
Last active June 23, 2019 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crypto-diaz/c36110bd357b0e422c4c7b17a9bed931 to your computer and use it in GitHub Desktop.
Save crypto-diaz/c36110bd357b0e422c4c7b17a9bed931 to your computer and use it in GitHub Desktop.
import json
import web3
from web3 import Web3
from web3.contract import ConciseContract
from web3.middleware import geth_poa_middleware
contract_name = 'name_registry'
abi_path = f'abi/{contract_name}.json'
with open(abi_path, 'r') as fp:
contract_abi = fp.read().strip()
bytecode_path = f'bytecode/{contract_name}.txt'
with open(bytecode_path, 'r') as fp:
contract_bytecode = fp.read().strip()
# web3.py instance
#w3 = Web3(Web3.EthereumTesterProvider())
from web3 import HTTPProvider
w3 = Web3(HTTPProvider('http://localhost:7545'))
#w3.middleware_stack.inject(geth_poa_middleware, layer=0)
# set pre-funded account as sender
w3.eth.defaultAccount = w3.personal.listAccounts[0]
# Instantiate and deploy contract
Greeter = w3.eth.contract(abi=contract_abi, bytecode=contract_bytecode)
# Submit the transaction that deploys the contract
tx_hash = Greeter.constructor().transact()
# Wait for the transaction to be mined, and get the transaction receipt
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
# Create the contract instance with the newly-deployed address
greeter = w3.eth.contract(
address=tx_receipt.contractAddress,
abi=contract_abi,
)
# Display the default greeting from the contract
name = b'crypto-diaz'
address = Web3.toChecksumAddress('0x5931188f0823fb076ed18618bbd89ef41e8655c1')
print('Calling contract register() function')
x = greeter.functions.register(name, address).transact()
print('lookup() name')
res = greeter.functions.lookup(name).call()
print(res)
#tx_hash = greeter.functions.setGreeting('Nihao').transact()
# Wait for transaction to be mined...
#w3.eth.waitForTransactionReceipt(tx_hash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment