Skip to content

Instantly share code, notes, and snippets.

@bguiz
Last active April 2, 2020 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bguiz/a0400b44bb0c3d0baa5f8e6db0c2ef22 to your computer and use it in GitHub Desktop.
Save bguiz/a0400b44bb0c3d0baa5f8e6db0c2ef22 to your computer and use it in GitHub Desktop.

Using Geth to attach to an RSK local node

/tutorials/ethereum-devs/geth-attach-local-node/ https://developers.rsk.co/tutorials/ethereum-devs/geth-attach-local-node/

Install java 8

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java 8.0.242-open
sdk install java 11.0.6-open
sdk use java 8.0.242-open
java -version

Download and verify RSKj 1.3.0

https://github.com/rsksmart/rskj/releases/tag/WASABI-1.3.0

cd ~/code/rsk
mkdir rskj-node
cd rskj-node
curl \
  -L \
  https://github.com/rsksmart/rskj/releases/download/WASABI-1.3.0/rskj-core-1.3.0-WASABI-all.jar \
  > ./rskj-core-1.3.0-WASABI-all.jar
curl \
  -L \
  https://github.com/rsksmart/rskj/releases/download/WASABI-1.3.0/SHA256SUMS.asc \
  > ./rskj-core-1.3.0-WASABI-all.SHA256SUMS.asc
sha256sum rskj-core-1.3.0-WASABI-all.jar
# 1343a100363d78db8c6563ec0778646b17af7fdaf7de2ac5932537582c079ddd  rskj-core-1.3.0-WASABI-all.jar
grep "rskj-core" rskj-core-1.3.0-WASABI-all.SHA256SUMS.asc
# 1343a100363d78db8c6563ec0778646b17af7fdaf7de2ac5932537582c079ddd rskj-core/build/libs/rskj-core-1.3.0-WASABI-all.jar

run rskj

java -cp ./rskj-core-1.3.0-WASABI-all.jar co.rsk.Start --regtest
# leave running, and open new terminal

Test that client is running

curl \
  localhost:4444/1.1.0/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
# {"jsonrpc":"2.0","id":1,"result":"0x63"}

Install geth 1.9.12

https://geth.ethereum.org/downloads/

mkdir -p ~/code/ethereum/geth-node
cd ~/code/ethereum/geth-node
curl \
  -L \
  https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-1.9.12-b6f1c8dc.tar.gz \
  > geth-alltools-linux-amd64-1.9.12-b6f1c8dc.tar.gz
tar -xf geth-alltools-linux-amd64-1.9.12-b6f1c8dc.tar.gz
cd geth-alltools-linux-amd64-1.9.12-b6f1c8dc
ls -l
# -rwxrwxr-x 1 bguiz bguiz 23310936 Mar 16 20:39 abigen
# -rwxrwxr-x 1 bguiz bguiz 22965752 Mar 16 20:39 bootnode
# -rwxrwxr-x 1 bguiz bguiz 34779600 Mar 16 20:39 clef
# -rwxrwxr-x 1 bguiz bguiz 22646312 Mar 16 20:39 evm
# -rwxrwxr-x 1 bguiz bguiz 37542864 Mar 16 20:39 geth
# -rwxrwxr-x 1 bguiz bguiz 16060528 Mar 16 20:39 puppeth
# -rwxrwxr-x 1 bguiz bguiz  3481283 Mar 16 20:39 rlpdump
# -rwxrwxr-x 1 bguiz bguiz 28710976 Mar 16 20:39 wnode
./geth version
# Version: 1.9.12-stable

Connect geth to RSKj

./geth attach http://127.0.0.1:4444
# Welcome to the Geth JavaScript console!
# instance: RskJ/1.3.0/Linux/Java1.8/WASABI-36f480d
# coinbase: 0xec4ddeb4380ad69b3e509baad9f158cdf4e4681d
# at block: 857 (Wed Apr 01 2020 16:42:45 GMT+0800 (+08))
#  modules: debug:1.0 eth:1.0 evm:1.0 net:1.0 personal:1.0 rpc:1.0 rsk:1.0 sco:1.0 trace:1.0 txpool:1.0 web3:1.0
> eth.blockNumber
895
> eth.blockNumber
898
> eth.gasPrice
0
> net.verison
undefined
> net.version
"33"
> net.peerCount
0
> personal.ListAccounts
undefined
> personal.listAccounts
["0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826", "0x7986b3df570230288501eea3d890bd66948c9b79", "0x0a3aa774752ec2042c46548456c094a76c7f3a79", "0xcf7cdbbb5f7ba79d3ffe74a0bba13fc0295f6036", "0x39b12c05e8503356e3a7df0b7b33efa4c054c409", "0xc354d97642faa06781b76ffb6786f72cd7746c97", "0xdebe71e1de41fc77c44df4b6db940026e31b0e71", "0x7857288e171c6159c5576d1bd9ac40c0c48a771c", "0xa4dea4d5c954f5fd9e87f0e9752911e83a3d18b3", "0x09a1eda29f664ac8f68106f6567276df0c65d859", "0xec4ddeb4380ad69b3e509baad9f158cdf4e4681d"]
> personal.listAccounts.length
11
> personal.newAccount('mypasswd')
"0x9fa8839bf69a476a7a4fa18108dc08184913e6d0"
> myNewAccount = '0x9fa8839bf69a476a7a4fa18108dc08184913e6d0'
> personal.listAccounts.length
12
> eth.getBalance(eth.accounts[1])
1e+30
> web3.fromWei(eth.getBalance(eth.accounts[1]), 'ether')
1000000000000
> web3.fromWei(eth.getBalance(myNewAccount), 'ether')
0
> eth.sendTransaction({ from: eth.accounts[1], to: myNewAccount, value: web3.toWei(300000000000, 'ether') "0x9e1e49528d687e7414ce7832bafa776ed387a84b504deb9a648c923ec5d756ba"
> web3.fromWei(eth.getBalance(eth.accounts[1]), 'ether')
Error: Post http://127.0.0.1:4444: read tcp 127.0.0.1:40712->127.0.0.1:4444: read: connection reset by peer
	at web3.js:6347:37(47)
	at web3.js:5081:62(37)
	at <eval>:1:28(10)

> web3.fromWei(eth.getBalance(eth.accounts[1]), 'ether')
700000000000
> web3.fromWei(eth.getBalance(myNewAccount), 'ether')
300000000000
> exit

Deploy a smart contract on an RSK local node using Geth and Remix

/tutorials/ethereum-devs/geth-attach-deploy-smart-contract/ https://developers.rsk.co/tutorials/ethereum-devs/geth-attach-deploy-smart-contract/

mkdir -p ~/code/rsk/rskj-node
cd ~/code/rsk/rskj-node
touch register.sol
touch register.js

register.sol

pragma solidity 0.5.4;

contract Register {
    string private info;

    function setInfo(string memory _info) public {
        info = _info;
    }

    function getInfo() public view returns (string memory) {
        return info;
    }
}

http://remix.ethereum.org/#optimize=false&evmVersion=null&version=soljson-v0.5.4+commit.9549d8ff.js

  • (main) Solidity
  • (files) + -> register.sol
  • (compiler) Compile register.sol
  • (compiler) Compilation Details -> scroll down -> Web3Deploy -> clipboard icon

register.js

var registerContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"getInfo","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_info","type":"string"}],"name":"setInfo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]);
var register = registerContract.new(
   {
     from: web3.eth.accounts[0],
     data: '0x608060405234801561001057600080fd5b50610323806100206000396000f3fe608060405234801561001057600080fd5b5060043610610053576000357c0100000000000000000000000000000000000000000000000000000000900480635a9b0b8914610058578063937f6e77146100db575b600080fd5b610060610196565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a0578082015181840152602081019050610085565b50505050905090810190601f1680156100cd5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610194600480360360208110156100f157600080fd5b810190808035906020019064010000000081111561010e57600080fd5b82018360208201111561012057600080fd5b8035906020019184600183028401116401000000008311171561014257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610238565b005b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561022e5780601f106102035761010080835404028352916020019161022e565b820191906000526020600020905b81548152906001019060200180831161021157829003601f168201915b5050505050905090565b806000908051906020019061024e929190610252565b5050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029357805160ff19168380011785556102c1565b828001600101855582156102c1579182015b828111156102c05782518255916020019190600101906102a5565b5b5090506102ce91906102d2565b5090565b6102f491905b808211156102f05760008160009055506001016102d8565b5090565b9056fea165627a7a7230582029d658dbf2310b466c0ceb356a33d707f9f7517119328840969be47b0ff2b01a0029',
     gas: '4700000'
   }, function (e, contract){
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 })
./geth attach http://127.0.0.1:4444

> loadScript('/home/bguiz/code/rsk/rskj-node/register.js')
Error: Post http://127.0.0.1:4444: EOF undefined
undefined
# Network error, try again

> loadScript('/home/bguiz/code/rsk/rskj-node/register.js')
null [object Object]
undefined
> null [object Object]
Contract mined! address: 0x77045e71a7a2c50903d88e564cd72fab11e82051 transactionHash: 0x3a567874dbc42aa47d9623dabf3faca9d45080b00a1f0265f04fb5f36ae2ec29

> register.
register._eth            register.address         register.constructor     register.setInfo
register.abi             register.allEvents       register.getInfo         register.transactionHash
> register.getInfo()
""
> register.setInfo("RSK", { from: eth.accounts[1] })
"0x5ec23790f6d9035753adf3372890f8a8a1105726e8cfefa0e89409025d2291bb"
> register.getInfo()
"RSK"
> exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment