2017-11-30 10 views
2

어떤 방법을 배포하는 것이 I 찾은 (this onethat one) 가장 좋은 방법은 계약서를 컴파일 한 다음 수동으로 geth에 삽입하는 것입니다.컴파일하고 <a href="https://github.com/ethereum/viper/issues/459" rel="nofollow noreferrer">GitHub issue</a> 두 개의 포스트에 따르면 (ethereum.tools에서하지 테스터 체인)</p> <p>를 컴파일하고 일부 사용자 지정 체인에 자동으로 바이퍼 스마트 계약을 배포하는 에테 리움 바이퍼 스마트 계약이 자동으로

누구나 솔루션을 공유 할 수 있습니까?

답변

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()))