MCPcopy Create free account
hub / github.com/CPChain/chain / main

Function main

docs/quickstart/contract.py:7–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5from cpc_fusion.contract import ConciseContract
6
7def main():
8 # Solidity source code
9 contract_source_code = '''
10 pragma solidity ^0.4.24;
11
12 contract Greeter {
13 string public greeting;
14 event test(address who,string a);
15 function Greeter() public {
16 greeting = 'Hello';
17 }
18
19 function setGreeting(string _greeting) public {
20 emit test(msg.sender,_greeting);
21 greeting = _greeting;
22 }
23
24 function greet() view public returns (string) {
25 return greeting;
26 }
27 }
28 '''
29 print(contract_source_code)
30
31 compiled_sol = compile_source(contract_source_code) # Compiled source code
32 contract_interface = compiled_sol['<stdin>:Greeter']
33
34 # web3.py instance
35 w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8501'))
36
37 # set pre-funded account as sender
38 w3.cpc.defaultAccount = w3.cpc.accounts[0]
39
40 # Instantiate and deploy contract
41 Greeter = w3.cpc.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])
42
43 # Submit the transaction that deploys the contract
44 # your keypath
45 # change the keypath to your keystore file
46 keypath = "//home/shi/chain/workspace/src/bitbucket.org/cpchain/chain/examples/cpchain/data/data21/keystore/key21"
47 # your password
48 password = "password"
49 # your account address
50 from_addr = w3.toChecksumAddress('0xb3801b8743dea10c30b0c21cae8b1923d9625f84')
51 tx_hash = Greeter.constructor().raw_transact({
52 # Increase or decrease gas according to contract conditions
53 'gas': 819776,
54 'from': from_addr,
55 'value': 0
56 }, keypath, password, 42)
57 # tx_hash = Greeter.constructor().transact()
58
59 # print('*********',w3.cpc.getTransactionReceipt(tx_hash_raw))
60 print('*********', w3.cpc.getTransactionReceipt(tx_hash))
61
62 # Wait for the transaction to be mined, and get the transaction receipt
63 tx_receipt = w3.cpc.waitForTransactionReceipt(tx_hash)
64 # tx_receipt1 = w3.cpc.waitForTransactionReceipt(tx_hash_raw)

Callers 1

contract.pyFile · 0.70

Calls 1

callMethod · 0.45

Tested by

no test coverage detected