Geth JavaScript console interacts with smart contracts

Source: Internet
Author: User
1. Intelligent Contract Srp.sol Content
Contract Simplestorage {
    uint Storeddata;

    function set (UINT x) {
        storeddata = x;
    }

    function get () constant returns (UINT RetVal) {return
        storeddata;
    }
}
2. Compile the intelligent contract
Solc--bin srp.sol
solc--bin Srp.sol

3.geth JavaScript Console 3.1 Piccgenesis.json Content

{"
  nonce": "0x0000000000000042", "
  difficulty": "0x020000",
  "Mixhash": " 0x0000000000000000000000000000000000000000000000000000000000000000 ","
  Coinbase ":" 0x0000000000000000000000000000000000000000 ","
  timestamp ":" 0x00 ",
  " Parenthash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ","
  extradata ":" 0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa ",
  " Gaslimit ":" 0X4C4B40 ",
  " config ": {
      "Chainid": 661566,
      "Homesteadblock": 0,
      "Eip155block": 0,
      "Eip158block": 0
  },
  "Alloc": {}
}

3.2 Linux Boot

Geth--datadir/ws/etherum/privatechain Init Piccgenesis.json

Geth--datadir/ws/etherum/privatechain/--rpc--syncmode full--networkid 661566 console
3.3 Windows startup

Geth--datadir D:\geth\chain Init Piccgenesis.json

Geth--datadir D:\geth\chain--rpc--syncmode full--networkid 661566 console 3.4 on the Geth JavaScript console follow the instructions below Can contract

Abi=[{"constant": false, "inputs": [{"Name": "X", "type": "uint256"}], "name": "Set", "outputs": [], "payable": false, " Statemutability ': ' nonpayable ', ' type ': ' function '},{' constant ': true, ' inputs ': [], ' name ': ' Get ', ' outputs ': [{' Name ':] ' RetVal ', ' type ': ' uint256 '}, ' payable ': false, ' statemutability ': ' View ', ' type ': ' function '} ' code= ' 0x6060604052341561000f57600080fd5b60d38061001d6000396000f3006060604052600436106049576000357c01000000000000000000000000000 00000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c14606e575b600080fd5b3415605857600080fd5b606c 60048080359060200190919050506094565b005b3415607857600080fd5b607e609e565b6040518082815260200191505060405180910390f35b80600 08190555050565b600080549050905600a165627a7a72305820471ae736fa67702f0c009e5653ff7b15c68fb6588b1ae4c28a8b8ed90c9084120029 "Personal.unlockaccount (eth.accounts[0]) mycontract = eth.contract (ABI) contract = Mycontract.new ({from:eth.accounts
[0],data:code,gas:1000000}]/generated contract transactions in the trading pool, need to be submitted to the block chain contract to be used. Contract = mycontract.at(Contract Address)//To obtain the contract instance from the block chain according to the contract address//log to the block chain before executing contract.set.sendTransaction (2,{from:eth.accounts[0]}) Contract.set.call (2)
Related Article

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.