Skip to content

Instantly share code, notes, and snippets.

@tpmccallum
Last active August 8, 2019 06:09
Show Gist options
  • Save tpmccallum/38b72dd46d9c3a5c76baa5c42fcba726 to your computer and use it in GitHub Desktop.
Save tpmccallum/38b72dd46d9c3a5c76baa5c42fcba726 to your computer and use it in GitHub Desktop.
The commands which I used to perform research, development and testing on the SecondState BaaS infrastructure

SecondState R&D

This file is a list of commands and links which I used to interact with the suite of SecondState tools and services.

Initialize SecondState Blockchain as a Service (BaaS)

Create new blockchain in just a few clicks at http://baas-mvp.secondstate.io/ Save the RPC endpoint and Smart Contract Search Engine URLs for our code below.

Install Ubuntu 18.04 Server and then run the following commands

sudo apt-get update
sudo apt install nodejs
sudo apt-get install npm

Install SecondState software

npm install web3-ss
npm install es-ss.js

ES-SS.JS via node command prompt

node
let esss = require("es-ss.js");
let ESSS = esss.ESSS;
var searchEngineProvider = new ESSS("GET_SEARCH_ENDPOINT_FROM_BAAS_OUTPUT_ABOVE")// Please note, do not include trailing slash on the URL here!

Web3-SS via node command prompt

node
var Web3 = require("web3-ss")
var web3 = new Web3(new Web3.providers.HttpProvider("GET_RPC_ENDPOINT_FROM_BAAS_OUTPUT_ABOVE"))
var abi = ABI_GENERATED_VIA_BUIDL_TOOL
var bytecode = BYTECODE_GENERATED_VIA_BUIDL_TOOL
var contract = web3.ss.contract(abi);
var data = '0x' + bytecode;

Set default account

web3.ss.defaultAccount = web3.ss.accounts[0];

Create a function to load the data into the search engine

function loadData(_abi, _txHash) {
    var abiSubmission = searchEngineProvider.submitAbi(abi, txHash);
    abiSubmission.then(function(result) {
            console.log("Result is " + result);
        })
        .catch(function() {
            console.log("Error");
        });
}

Create a new contract instance and then call the loadData function

contract.new({
  data: data,
}, function (ee, i) {
    if (!ee && i.address != null) {
        console.log("Created item");
        setTimeout(function() {
            loadData(abi, i.transactionHash)
        }, 5 * 1000);
    }
});

Example

Here is a complete example of node syntax, using real data (actual contract and BaaS chain)

let esss = require("es-ss.js");

let ESSS = esss.ESSS;

var searchEngineProvider = new ESSS("https://3-112-36-0.baas.secondstate.io")

var Web3 = require("web3-ss")

var web3 = new Web3(new Web3.providers.HttpProvider("https://3-113-10-239.baas.secondstate.io:9545"))

var abi = [{
    "constant": false,
    "inputs": [{
        "name": "x",
        "type": "uint256"
    }],
    "name": "set",
    "outputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
}, {
    "constant": true,
    "inputs": [],
    "name": "get",
    "outputs": [{
        "name": "",
        "type": "uint256"
    }],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
}]

var bytecode = "608060405234801561001057600080fd5b5060df8061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080549050905600a165627a7a723058208cc6da6bb0565c3213219d167226eb4ff952e6d1bc2eef0fa542fbb9922666350029"

var contract = web3.ss.contract(abi);

var data = '0x' + bytecode;

web3.ss.defaultAccount = web3.ss.accounts[0];

function loadData(_abi, _txHash) {
    var abiSubmission = searchEngineProvider.submitAbi(abi, txHash);
    abiSubmission.then(function(result) {
            console.log("Result is " + result);
        })
        .catch(function() {
            console.log("Error");
        });
}

contract.new({
    data: data,
}, function(ee, i) {
    if (!ee && i.address != null) {
        console.log("Created item");
        setTimeout(function() {
            loadData(abi, i.transactionHash)
        }, 5 * 1000);
    } else {
        console.log("Error");
        console.log(ee);
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment