Deploying smart contracts on Geth clients __ block chain

Source: Internet
Author: User
Https://www.cnblogs.com/fengzhiwu/p/5629468.html on Geth deploy and invoke the full tutorial on smart contracts deploy smart contracts on Geth clients 1, write smart contract source code source= "contract Test {function Multiply (uint a) returns (UINT D) {return a * 7;}} "; 2, compile the intelligent contract contract = eth.compile.solidity (source). Test; This approach requires installing the solidity compiler SOLC on the Geth client, which I have not yet found a solution for later research. I compile the smart contract with the truffle client, and after compiling it, generate a corresponding JSON file for the contract. Open the JSON file and find the ABI and bytecode defined on the Geth client. var abi=[{"constant": false, "inputs": [{"Name": "A", "type": "uint256"}], "name": "Multiply", "outputs": [{' name ': '] ' Type ': ' uint256 '}], ' payable ': false, ' statemutability ': ' nonpayable ', ' type ': ' function '}]; var code= " 0x6060604052341561000f57600080fd5b60b18061001d6000396000f300606060405260043610603f576000357c01000000000000000000000000000 00000000000000000000000000000900463ffffffff168063c6888fa1146044575b600080fd5b3415604e57600080fd5b606260048080359060200190 919050506078565b6040518082815260200191505060405180910390f35b60006008820290509190505600a165627a7a72305820af1e3196bec2eb276 a849a388e9c47ad20541b590c500c78c062d516b5b8de680029 "; 3, the creation of Intelligent contract Object Mycontract=eth.contract (ABI); 4, the deployment of contracts. The deployment contract is to send a transaction to the ether, the destination address is not written is sent to the block chain contract=mycontract.new ({from:eth.accounts[0],data:code}); At this point, you may be prompted to account is not available, is not unlocked, with Personal.unlockaccount () unlocked, and then deployed after deployment to view contract, found that address is undefined, this is because the transaction was sent out, No miners dug up the mine and didn't write it into the block chain, so they didn't know. Can be viewed with Txpool.status to 5, start digging Miner.start (); Admin.sleepblocks (); Miner.stop (); After digging, the transaction is written into the block chain, then look at the contract can see the address. In this way, the smart contract is successfully deployed in the ether square.
Example of a deployment contract, var browser_test_sol_test = browser_test_sol_testcontract.new with gas values and functions (    {     from: web3.eth.accounts[0],       data:   ' 0x6060604052341561000f57600080fd5b61014f8061001e6000396000f300606060405260043610610062576000357c0100000000000000000000000 000000000000000000000000000000000900463ffffffff16806303b067c1146100675780632d74eb541461008a57806341c0e1b5146100b3578063b1 976a02146100c8575b600080fd5b341561007257600080fd5b61008860048080359060200190919050506100f1565b005b341561009557600080fd5b6 1009d6100fb565b6040518082815260200191505060405180910390f35b34156100be57600080fd5b6100c6610101565b005b34156100d357600080fd 5b6100db61011a565b6040518082815260200191505060405180910390f35b8060008190555050565b60005481565b3373fffffffffffffffffffffff fffffffffffffffff16ff5b600080549050905600a165627a7a72305820bbd6b703b7105d973e93a71195c628268c59227321b4f6f3aa1c3a2b510525 950029 ',       gas:  ' 4700000 '    }, function  (e, contract) {     Console.log (e, contract);     if  (typeof contract.address !==  ' undefined ')  {          console.log (' contract mined! address:  '  +  contract.address +  '  transactionHash:  '  + contract.transactionhash);     }  })

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.