Giter Club home page Giter Club logo

cryptoworkshop's Introduction

How to write and deploy your first smart contract on RSK

Setting up environment

Prerequisites

Setting up RSK node

To install a node you should simply follow the wiki here.

Once installed, start it up pointing to regtest (to avoid the need to sync with testnet or mainnet).

If you are using the fatjar you should simply run the following command:

java -cp <PATH-TO-THE-RSKJ-FATJAR> co.rsk.Start --regtest

Additional configuration

You will have to configure the network were you will be deploying your contracts. To do so go to truffle-config.js and uncomment the existing networks or add a new one. The file comes with a thourough explanation on how to do it.

To configure the default regtest rskj network you can use this:

    rsk: {
      host: "127.0.0.1",
      port: 4444,
      network_id: "*"
    }

How to deploy the contract

Start a console and use truffle to deploy your contract:

$truffle console --network development
truffle(development)> migrate --reset
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================

1_initial_migration.js
======================
2_hello.js
==========
   > contract address:    0x9d4f182E71e3c19f3b706afB78F103C6175a517a
truffle(development)> 

The value for network is configure in truffle-config.js write doen the contract address as you will need it to interact with it!!!

How to use it

Start a console and use truffle and web3js to interact with the previously deployed contract:

$truffle console --network development
truffle(development)> var hello;
truffle(development)> Hello.at('0x9d4f182E71e3c19f3b706afB78F103C6175a517a').then((i) => hello = i);
truffle(development)> hello.getGreeting()
'hello world'
truffle(development)> hello.setGreeting('hola cryptoPatagonia!')
{ tx: '0x25ed67f19fde3a2bec1625254ae339209c2fca83ec37534ac746fab7921ca409',
  receipt: 
   { transactionHash: '0x25ed67f19fde3a2bec1625254ae339209c2fca83ec37534ac746fab7921ca409',
     transactionIndex: 0,
     blockHash: '0xe01985f63575aeaaf9d12ea9702e70c876e324d34c18b64f694b8c7e987efaf1',
     blockNumber: 14,
     from: '0x20931a15dae5a194cde4a568892c907a5de587e8',
     to: '0x9d4f182e71e3c19f3b706afb78f103c6175a517a',
     gasUsed: 29480,
     cumulativeGasUsed: 29480,
     contractAddress: null,
     logs: [],
     status: true,
     logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
     v: '0x1c',
     r: '0xf16585dfc97a0dcdec86439975c04e26ee7feec66001cf70973f84b2e1c849fd',
     s: '0x5142de084db57bee1f74abf6967389654ee263a0236e60f8e7e98a53ce1f9fbd',
     rawLogs: [] },
  logs: [] }
truffle(development)> hello.getGreeting()
'hola cryptoPatagonia!'

As you can see, the original value of greet was the one we set in the constructor, but we were able to change it by calling the set method, which created a transaction to persist the storage change.

cryptoworkshop's People

Contributors

josedahlquist avatar

Watchers

 avatar

Forkers

varanot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.