Skip to content

Use Contract

zychenchun edited this page Sep 9, 2018 · 1 revision

Deploy A Simple Contract

IDE

A simple smart contract example that relies on Remix

1. Prepare Remix

The following demonstration is done using the local version(remix_0.7.0).

  • install remix
unzip remix-ide-0.7.0.zip
cd remix-ide
npm install
npm run setupremix  # this will clone https://github.com/ethereum/remix for you and link it to remix-ide. Only execute this step if you want to contribute on Remix development
npm start

2. Compile Contract

Prepare the smart contract source code:

pragma solidity ^0.4.0;

contract SimpleAdd {
    uint a;
    
    function add(uint x) {
        a+=x;
    }

    function get() constant returns(uint) {
        return a;
    }
}

Copy the smart contract source code to the text area and click the Start to compile on the right to start compile.

3. Deploy Contract

  1. Select Run on the right, as shown in the picture with an arrow point to it.

  2. Point deploy button to deploy contract.

  3. Copy transaction input:

0x608060405234801561001057600080fd5b5060e78061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631003e2d214604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60b2565b6040518082815260200191505060405180910390f35b80600080828254019250508190555050565b600080549050905600a165627a7a7230582019ed2ee3d2c622567ce95b784d20c851d723a7f3bd5c3edc805623363937003b0029
  1. Send transaction to uranus:
request: 

curl -X POST -d '{"id": 1, "method": "Uranus.SignAndSendTransaction", "params": [{"From": "0xfF38733Cc8433a6Ad934908525488423Bd7008ca","Gas": "0x9f759", "GasPrice": "0x9184e72a000", "Data": "0x608060405234801561001057600080fd5b5060e78061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631003e2d214604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60b2565b6040518082815260200191505060405180910390f35b80600080828254019250508190555050565b600080549050905600a165627a7a7230582019ed2ee3d2c622567ce95b784d20c851d723a7f3bd5c3edc805623363937003b0029","Passphrase":"coinbase"}]}' http://localhost:8000

result: 

{"id":1,"result":"0x737047a78114d48d9da4f94ff40fbdee7c7960ed254a15ec5c94bae7204c198f","error":null}

4. Test Add Function

  1. Point add button to test add function.

  2. Copy transaction input:

0x1003e2d2000000000000000000000000000000000000000000000000000000000000000a
  1. Send transaction to test contract add function:
request: 

curl -X POST -d '{"id": 1, "method": "Uranus.SignAndSendTransaction", "params": [{"From": "0xfF38733Cc8433a6Ad934908525488423Bd7008ca","To":"0xF22469188Fe0dF43E74561C23f5d2A959Cd74E9c","Gas": "0x9f759", "GasPrice": "0x9184e72a000", "Data": "0x1003e2d2000000000000000000000000000000000000000000000000000000000000000a","Passphrase":"coinbase"}]}' http://localhost:8000

result:

{"id":1,"result":"0x32194e491d52040861e476382a6e8a6ffdd2cb43dbf969e534eea899f063cb07","error":null}


5. Test Get Function

  1. Point get button to test get function.

  2. Copy transaction input:

0x6d4ce63c
  1. Send transaction to test contract get function:

request:

curl -X POST -d '{"id": 1, "method": "Uranus.Call", "params": [{"From": "0xfF38733Cc8433a6Ad934908525488423Bd7008ca","To":"0xF22469188Fe0dF43E74561C23f5d2A959Cd74E9c","Gas": "0x9f759", "GasPrice": "0x9184e72a000", "Data": "0x6d4ce63c","BlockHeight":-1}]}' http://localhost:8000

result: 

{"id":1,"result":"0x000000000000000000000000000000000000000000000000000000000000000a","error":null}

Clone this wiki locally