{ "config": { "chainId": 1907, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "difficulty": "40", "gasLimit": "5100000", "alloc": {} }
geth --datadir node1 account new
geth --datadir node1 init genesis.json
geth --datadir node1 --nodiscover --mine --minerthreads 1 --maxpeers 0 --verbosity 3 --networkid 98765 --rpc --rpcapi="db,eth,net,web3,personal,web3" console
geth --datadir node1 --networkid 98765 attach ipc://home/frolov/node1/geth.ipc
pragma solidity ^0.4.10; contract HelloSol { string savedString; uint savedValue; address contractOwner; function HelloSol(uint initValue, string initString) public { contractOwner = msg.sender; savedString = initString; savedValue = initValue; } function setString( string newString ) public { savedString = newString; } function getString() public constant returns( string curString) { return savedString; } function setValue( uint newValue ) public { savedValue = newValue; } function getValue() public constant returns( uint curValue) { return savedValue; } function setAll(uint newValue, string newString) public { savedValue = newValue; savedString = newString; } function getAll() public constant returns( uint curValue, string curString) { return (savedValue, savedString); } function getAllEx() public constant returns( bool isOk, address msgSender, uint curValue, string curString, uint val1, string str1, uint val2, uint val3) { string memory sss="++ ==================================== ++"; return (true, msg.sender, 33333, sss, 9999, "Line 9999", 7777, 8888); } function repiter(bool pBool, address pAddress, uint pVal1, string pStr1, uint pVal2, string pStr2, uint pVal3, int pVal4) public pure returns( bool rbBool, address rpAddress, uint rpVal1, string rpStr1, uint rpVal2, string rpStr2, uint rpVal3, int rpVal4) { return (pBool, pAddress, pVal1, pStr1, pVal2, pStr2, pVal3, pVal4); } }
#!/usr/bin/perl use strict; use Net::Ethereum; use Data::Dumper; my $contract_name = $ARGV[0]; my $password = $ARGV[1]; my $node = Net::Ethereum->new('http://localhost:8545/'); my $src_account = $node->eth_accounts()->[0]; print 'My account: '.$src_account, "\n"; my $constructor_params={}; $constructor_params->{ initString } = '+ Init string for constructor +'; $constructor_params->{ initValue } = 102; my $contract_status = $node->compile_and_deploy_contract($contract_name, $constructor_params, $src_account, $password); my $new_contract_id = $contract_status->{contractAddress}; my $transactionHash = $contract_status->{transactionHash}; my $gas_used = hex($contract_status->{gasUsed}); print "\n", 'Contract mined.', "\n", 'Address: '.$new_contract_id, "\n", 'Transaction Hash: '.$transactionHash, "\n"; my $gas_price=$node->eth_gasPrice(); my $contract_deploy_price = $gas_used * $gas_price; my $price_in_eth = $node->wei2ether($contract_deploy_price); print 'Gas used: '.$gas_used.' ('.sprintf('0x%x', $gas_used).') wei, '.$price_in_eth.' ether', "\n\n";
my $cmd = "$bin_solc --bin --abi $contract_src_path -o build --overwrite";
use Net::Ethereum; use Data::Dumper; my $contract_name = $ARGV[0]; my $password = $ARGV[1]; my $contract_id = $ARGV[2]; my $node = Net::Ethereum->new('http://localhost:8545/'); my $src_account = $node->eth_accounts()->[0]; print 'My account: '.$src_account, "\n"; my $abi = $node->_read_file('build/'.$contract_name.'.abi'); $node->set_contract_abi($abi); $node->set_contract_id($contract_id); # Call contract methods without transactions my $function_params={}; my $test1 = $node->contract_method_call('getValue', $function_params); print Dumper($test1); my $test = $node->contract_method_call('getString'); print Dumper($test); my $testAll = $node->contract_method_call('getAll'); print Dumper($testAll); my $testAllEx = $node->contract_method_call('getAllEx'); print Dumper($testAllEx); $function_params={}; $function_params->{ pBool } = 1; $function_params->{ pAddress } = "0xa3a514070f3768e657e2e574910d8b58708cdb82"; $function_params->{ pVal1 } = 1111; $function_params->{ pStr1 } = "This is string 1"; $function_params->{ pVal2 } = 222; $function_params->{ pStr2 } = "And this is String 2, very long string +++++++++++++++++========="; $function_params->{ pVal3 } = 333; $function_params->{ pVal4 } = '-999999999999999999999999999999999999999999999999999999999999999977777777'; my $rc = $node->contract_method_call('repiter', $function_params); print Dumper($rc); # Send Transaction 1 my $rc = $node->personal_unlockAccount($src_account, $password, 600); print 'Unlock account '.$src_account.'. Result: '.$rc, "\n"; my $function_params={}; $function_params->{ newString } = '+++ New string for save +++'; my $used_gas = $node->contract_method_call_estimate_gas('setString', $function_params); my $gas_price=$node->eth_gasPrice(); my $transaction_price = $used_gas * $gas_price; my $call_price_in_eth = $node->wei2ether($transaction_price); print 'Estimate Transaction Gas: '.$used_gas.' ('.sprintf('0x%x', $used_gas).') wei, '.$call_price_in_eth.' ether', "\n"; my $tr = $node->sendTransaction($src_account, $node->get_contract_id(), 'setString', $function_params, $used_gas); print 'Waiting for transaction: ', "\n"; my $tr_status = $node->wait_for_transaction($tr, 25, $node->get_show_progress()); print Dumper($tr_status); # Send Transaction 2 $rc = $node->personal_unlockAccount($src_account, $password, 600); print 'Unlock account '.$src_account.'. Result: '.$rc, "\n"; $function_params={}; $function_params->{ newValue } = 77777; $used_gas = $node->contract_method_call_estimate_gas('setValue', $function_params); $transaction_price = $used_gas * $gas_price; $call_price_in_eth = $node->wei2ether($transaction_price); print 'Estimate Transaction Gas: '.$used_gas.' ('.sprintf('0x%x', $used_gas).') wei, '.$call_price_in_eth.' ether', "\n"; $tr = $node->sendTransaction($src_account, $node->get_contract_id(), 'setValue', $function_params, $used_gas); print 'Waiting for transaction: ', "\n"; $tr_status = $node->wait_for_transaction($tr, 25, $node->get_show_progress()); print Dumper($tr_status); $testAllEx = $node->contract_method_call('getAllEx'); print Dumper($testAllEx);
my $abi = $node->_read_file('build/'.$contract_name.'.abi'); $node->set_contract_abi($abi); $node->set_contract_id($contract_id);
$function_params={}; $function_params->{ pBool } = 1; $function_params->{ pAddress } = "0xa3a514070f3768e657e2e574910d8b58708cdb82"; $function_params->{ pVal1 } = 1111; $function_params->{ pStr1 } = "This is string 1"; $function_params->{ pVal2 } = 222; $function_params->{ pStr2 } = "And this is String 2, very long string +++++++++++++++++========="; $function_params->{ pVal3 } = 333; $function_params->{ pVal4 } = '-999999999999999999999999999999999999999999999999999999999999999977777777'; my $rc = $node->contract_method_call('repiter', $function_params); print Dumper($rc);
my $function_params={}; $function_params->{ newString } = '+++ New string for save +++'; my $used_gas = $node->contract_method_call_estimate_gas('setString', $function_params); my $gas_price=$node->eth_gasPrice(); my $transaction_price = $used_gas * $gas_price; my $call_price_in_eth = $node->wei2ether($transaction_price); print 'Estimate Transaction Gas: '.$used_gas.' ('.sprintf('0x%x', $used_gas).') wei, '.$call_price_in_eth.' ether', "\n"; my $tr = $node->sendTransaction($src_account, $node->get_contract_id(), 'setString', $function_params, $used_gas); print 'Waiting for transaction: ', "\n"; my $tr_status = $node->wait_for_transaction($tr, 25, $node->get_show_progress()); print Dumper($tr_status);
Source: https://habr.com/ru/post/346234/
All Articles