Last active
November 29, 2017 18:56
-
-
Save val314159/c8807758cc98bfdfd18dfc060d030c11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.ve3 | |
ve | |
account | |
password | |
dd | |
tx_hash | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import web3 | |
from web3 import Web3, HTTPProvider, TestRPCProvider | |
from solc import compile_source | |
from web3.contract import ConciseContract | |
# Solidity source code | |
contract_source_code = ''' | |
pragma solidity ^0.4.0; | |
contract Greeter { | |
string public greeting; | |
function Greeter() { | |
greeting = 'Hello'; | |
} | |
function setGreeting(string _greeting) public { | |
greeting = _greeting; | |
} | |
function greet() constant returns (string) { | |
return greeting; | |
} | |
} | |
''' | |
compiled_sol = compile_source(contract_source_code) # Compiled source code | |
contract_interface = compiled_sol['<stdin>:Greeter'] | |
# web3.py instance | |
from sys import argv | |
w3 = Web3(HTTPProvider(argv[1])) | |
# Instantiate and deploy contract | |
contract = w3.eth.contract(contract_interface['abi'], bytecode=contract_interface['bin']) | |
# Get transaction hash from deployed contract | |
tx_hash = contract.deploy(transaction={'from': w3.eth.accounts[0], 'gas': 410000}) | |
print(tx_hash) | |
''' | |
# Get tx receipt to get contract address | |
tx_receipt = w3.eth.getTransactionReceipt(tx_hash) | |
print('tx_receipt', tx_receipt) | |
contract_address = tx_receipt['contractAddress'] | |
print('contract_address', contract_address) | |
''' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:16.04 | |
RUN apt-get update -y && apt-get install -y apt-utils && apt-get upgrade -y | |
RUN apt-get install -y python3-pip python3-virtualenv virtualenv uuid-runtime python3-gevent python3-bottle software-properties-common | |
RUN add-apt-repository ppa:ethereum/ethereum | |
RUN apt-get update -y | |
RUN apt-get install -y emacs-nox tree solc libssl-dev geth screen git | |
RUN pip3 install -U py-solc populus pip | |
RUN git clone https://gist.github.com/val314159/c8807758cc98bfdfd18dfc060d030c11 /root/next-steps | |
WORKDIR /root/next-steps | |
RUN make .ve3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"config": { | |
"chainId": 130031, | |
"homesteadBlock": 0, | |
"eip155Block": 0, | |
"eip158Block": 0 | |
}, | |
"difficulty": "200", | |
"gasLimit": "2100000", | |
"alloc": {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import web3 | |
from web3 import Web3, HTTPProvider, TestRPCProvider | |
from solc import compile_source | |
from web3.contract import ConciseContract | |
# Solidity source code | |
contract_source_code = ''' | |
pragma solidity ^0.4.0; | |
contract Greeter { | |
string public greeting; | |
function Greeter() { | |
greeting = 'Hello'; | |
} | |
function setGreeting(string _greeting) public { | |
greeting = _greeting; | |
} | |
function greet() constant returns (string) { | |
return greeting; | |
} | |
} | |
''' | |
compiled_sol = compile_source(contract_source_code) # Compiled source code | |
contract_interface = compiled_sol['<stdin>:Greeter'] | |
# web3.py instance | |
from sys import argv | |
w3 = Web3(HTTPProvider(argv[1])) | |
tx_hash = argv[2] | |
print("tx_hash",tx_hash) | |
# Get tx receipt to get contract address | |
tx_receipt = w3.eth.getTransactionReceipt(tx_hash) | |
print('tx_receipt', tx_receipt) | |
contract_address = tx_receipt['contractAddress'] | |
print('contract_address', contract_address) | |
# Contract instance in concise mode | |
contract_instance = w3.eth.contract(contract_interface['abi'], contract_address, ContractFactoryClass=ConciseContract) | |
print('contract_instance', contract_instance) | |
# Getters + Setters for web3.eth.contract object | |
print('Contract value: {}'.format(contract_instance.greet())) | |
contract_instance.setGreeting('Nihao', transact={'from': w3.eth.accounts[0]}) | |
print('Setting value to: Nihao') | |
print('Contract value: {}'.format(contract_instance.greet())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To see this in action: look at http://b.ccl.io/2017/11/28/ethereum-next-steps | |
GETH=geth --datadir dd | |
all: run | |
docker-run: docker-build | |
/usr/local/bin/docker run -it -w `pwd` -v `pwd`:`pwd` xx | |
docker-build: | |
/usr/local/bin/docker build -t xx . | |
clean: | |
rm -fr dd account password .ve3 *~ .*~ tx_hash | |
dd: account | |
$(GETH) init g.js | |
attach: | |
$(GETH) attach dd/geth.ipc | |
account: | |
uuidgen > password | |
$(GETH) account new --password password >account | |
perl -i -npe 's/Address: {(.*?)}/$$1/g' account | |
run: dd | |
$(GETH) --mine --nodiscover --maxpeers 0 --networkid 130031 --rpc --rpccorsdomain "*" --rpcport 8545 --unlock 0 --password password --rpcapi web3,eth,personal,net,db,shh | |
get-bal: | |
curl http://localhost:8545 --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x'`cat account`'", "latest"],"id":1}' | |
.ve3: | |
virtualenv -p python3 .ve3 | |
.ve3/bin/pip install web3 py-solc ipython populus | |
tx_hash: .ve3 | |
.ve3/bin/python deploy.py http://localhost:8545 | tee tx_hash | |
interact: .ve3 tx_hash | |
.ve3/bin/python interact.py http://localhost:8545 `cat tx_hash` | |
unlock: .ve3 | |
.ve3/bin/python unlockAccount.py http://localhost:8545 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import web3 | |
from web3 import Web3, HTTPProvider, TestRPCProvider | |
from solc import compile_source | |
from web3.contract import ConciseContract | |
# Solidity source code | |
contract_source_code = ''' | |
pragma solidity ^0.4.0; | |
contract Greeter { | |
string public greeting; | |
function Greeter() { | |
greeting = 'Hello'; | |
} | |
function setGreeting(string _greeting) public { | |
greeting = _greeting; | |
} | |
function greet() constant returns (string) { | |
return greeting; | |
} | |
} | |
''' | |
compiled_sol = compile_source(contract_source_code) # Compiled source code | |
contract_interface = compiled_sol['<stdin>:Greeter'] | |
# web3.py instance | |
from sys import argv | |
w3 = Web3(HTTPProvider(argv[1])) | |
a = open('account').read().strip() | |
p = open('password').read().strip() | |
print(a) | |
print(p) | |
print(w3.eth.coinbase) | |
print(w3.eth.accounts) | |
print(w3.personal.unlockAccount('0x'+a,p)) | |
#w3.personal.unlockAccount(a,p) | |
#w3.eth.personal.unlockAccount( | |
#w3.personal.Personal.unlockAccount( | |
# open('account').read(), | |
# open('password').read()) | |
# Instantiate and deploy contract | |
#contract = w3.eth.contract(contract_interface['abi'], bytecode=contract_interface['bin']) | |
## Get transaction hash from deployed contract | |
#tx_hash = contract.deploy(transaction={'from': w3.eth.accounts[0], 'gas': 410000}) | |
#print(tx_hash) | |
''' | |
# Get tx receipt to get contract address | |
tx_receipt = w3.eth.getTransactionReceipt(tx_hash) | |
print('tx_receipt', tx_receipt) | |
contract_address = tx_receipt['contractAddress'] | |
print('contract_address', contract_address) | |
''' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment