2017-11-30 15 views
2

いくつかのカスタム・チェーン(ethereum.toolsからではないテスターチェーン)コンパイルし、そのI <a href="https://github.com/ethereum/viper/issues/459" rel="nofollow noreferrer">GitHub issue</a>と2つのポストによると、そこには、自動的に

に自動的バイパースマート契約をコンパイルしてデプロイする方法をイーサリアムバイパースマート契約を展開(this onethat one)、最良の選択肢は、契約をコンパイルしてからgethに手動で挿入することです。

誰でもソリューションを共有できますか?

答えて

1

Github issueに記載されているように、web3.pyライブラリとViperライブラリを使用することで実現できます。
おそらくあなたのニーズをカバーするスクリプトの例です:

from web3 import Web3, HTTPProvider 
from viper import compiler 
from web3.contract import ConciseContract 
from time import sleep 

example_contract = open('./path/to/contract.v.py', 'r') 
contract_code = example_contract.read() 
example_contract.close() 

cmp = compiler.Compiler() 
contract_bytecode = cmp.compile(contract_code).hex() 
contract_abi = cmp.mk_full_signature(contract_code) 

web3 = Web3(HTTPProvider('http://localhost:8545')) 
web3.personal.unlockAccount('account_addr', 'account_pwd', 120) 

# Instantiate and deploy contract 
contract_bytecode = web3.eth.contract(contract_abi, bytecode=contract_bytecode) 

# Get transaction hash from deployed contract 
tx_hash = contract_bytecode.deploy(transaction={'from': 'account_addr', 'gas': 410000}) 

# Waiting for contract to be delpoyed 
i = 0 
while i < 5: 
    try: 
     # Get tx receipt to get contract address 
     tx_receipt = web3.eth.getTransactionReceipt(tx_hash) 
     contract_address = tx_receipt['contractAddress'] 
     break # if success, then exit the loop 
    except: 
     print("Reading failure for {} time(s)".format(i + 1)) 
     sleep(5+i) 
     i = i + 1 
     if i >= 5: 
      raise Exception("Cannot wait for contract to be deployed") 

# Contract instance in concise mode 
contract_instance = web3.eth.contract(contract_abi, contract_address, ContractFactoryClass=ConciseContract) 

# Calling contract method 
print('Contract value: {}'.format(contract_instance.some_method())) 
関連する問題

 関連する問題