Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 2, 2021 02:07 am GMT

Deploying 'HelloWorld' on Vapory

Vapory is a new blockchain with a growing set of supporting technology. This tutorial covers the basics of deploying a smart contract on the Vapory Network using Node.js, Gvap, and the Vapory Flavored Solidity Compiler. Vapory currently offers no public network for testing and only miners produce the vapors needed to publish HelloWorld. Vapory was developed by an army of two and the status of the network can be checked anytime at https://status.vapory.org

Step One - Create a Vapory Development Environment

This article will not cover every step in the methods of forging the perfect development environment for Vapory. There are simply too many external variables to factor into the action of doing so.
It will cover the versions used by the author to provide guidance enough to execute success.

Ubuntu is the OS of choice used by the Vapory Team. 20.04 was used for this article. Windows 10 works just fine with Vapory. GCC (Ubuntu 9.3.0-17ubuntu1~20.04) / Clang (10.0.0-4ubuntu1) and Go (version go1.15.6 linux/amd64) are required to build Gvap (https://github.com/vaporyco/go-vapory) on Linux. Vapory.js (https://github.com/vaporyjs) and Vapory Web3.js (https://github.com/vaporyco/web.js) suggest support of Node.js LTS/Fermium, however, this real world exercise proved that there are several issues to resolve with those packages. Being that Node.js LTS/Dubnium is stable for use of Vapory JS Modules, it was selected for deployment. Refer to the Vapory Wiki (https://github.com/vaporyco/go-vapory/wiki) on how to setup gvap to serve rpc requests and create accounts using the JavaScript console.

Step Two - Build the Vapory Flavored Solidity Compiler

If no other version of Solidity is present on the system, the compiler may be installed using:

npm install -g @vapory/solc

If any other version Solidity is currently installed, the Vapory Flavored Solidity Compiler should be independently built to avoid the resulting system conflicts that will arise in not doing so. Download Boost 1.65.1 from https://boost.org and then extract the archive to a location of choice. Build boost using these two commands:

./bootstrap.sh./b2 -j 4

Now download the compiler from https://github.com/vaporyco/solidity/archive/refs/heads/master.zip or clone it from https://github.com/vaporyco/solidity.git and enter its directory. Execute the following commands on Ubuntu:

git submodule update --init --recursivemkdir buildcd buildcmake .. && make

Voila! Vapory Flavored Solidity (solc) will now be in the solc directory. Execute solc --help to confirm that the compiler functions on the system.

Step Three - Create a Vapory Smart Contract Node.js Package

A Node.js package is not necessarily required to use Node.js to deploy a smart contract to the Vapory Network. It is required to remove the warnings received while installing the dependencies for Vapory Web3.js when using Node.js and is just good practice. For this tutorial, Version 0.20.4-b of Vapory Web3.js was utilized and it may be installed using:

npm install @vapory/[email protected] --save

Within this package create hello.sol and add the following as its contents:

// HelloWorldpragma solidity >=0.4.0 <0.7.0;contract HelloWorld {    function get()public pure returns (string memory){        return 'Hello World!';    }}

Now create deploy.js and add the following as its contents:

// Copyright 2017 https://tokenmarket.net - MIT licensed//// Run with Node 7.x as://// node --harmony-async-await  deploy.js//let fs = require("fs");let Web3 = require('@vapory/web3'); // Create a vapory web3 connection to a running gvap node over JSON-RPC running at// http://localhost:8575// For geth VPS server + SSH tunneling see// https://gist.github.com/miohtama/ce612b35415e74268ff243af645048f4let web3 = new Web3();web3.setProvider(new web3.providers.HttpProvider('http://localhost:8575'));// Read the compiled contract code// Compile with// solc SampleContract.sol --combined-json abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,srcmap,srcmap-runtime,userdoc > contracts.jsonlet source = fs.readFileSync("contracts.json");let contracts = JSON.parse(source)["contracts"];//console.log(contracts);// ABI description as JSON structurelet abi = JSON.parse(contracts['hello.sol:HelloWorld'].abi);// Smart contract VVM bytecode as hexlet code = '0x' + contracts['hello.sol:HelloWorld'].bin;// Create Contract proxy classlet SampleContract = web3.vap.contract(abi);// Unlock the coinbase account to make transactions out of itconsole.log("Unlocking coinbase account");var password = "";try {  web3.personal.unlockAccount(web3.vap.coinbase, password,300);} catch(e) {  console.log(e);  return;}console.log("Deploying the contract");let contract = SampleContract.new({from: web3.vap.coinbase, gas: 1000000, data: code});// Transaction has entered to gvap memory poolconsole.log("Your contract is being deployed in transaction at http://vaporscan.com/tx/" + contract.transactionHash);//console.log(contract);// http://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleepfunction sleep(ms) {  return new Promise(resolve => setTimeout(resolve, ms));}// We need to wait until any miner has included the transaction// in a block to get the address of the contract(async function () {  while (true) {    var deploy = {from:web3.vap.coinbase, data:code, gas: 2000000};    var getVContractInstance = SampleContract.new('', deploy);    let receipt = web3.vap.getTransactionReceipt(getVContractInstance.transactionHash);    if (receipt && receipt.contractAddress) {      console.log("Your contract has been deployed at http://vaporscan.com/addr/" + receipt.contractAddress);      console.log("Note that it might take 30 - 90 sceonds for the block to propagate befor it's visible in vaporscan.com");      break;    }    console.log("Waiting a mined block to include your contract... currently in block " + web3.vap.blockNumber);    await sleep(10000);  }})().catch( e => { console.error(e) });

The password should be set to corresponding credentials

Step Four - Compile and Deploy the Vapory Smart Contract

Compile hello.sol using the following command:

solc hello.sol --combined-json abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,srcmap,srcmap-runtime,userdoc > contracts.json

Next - deploy:

node deploy.js

A Transaction Hash will output along with an expected Node.js error. Due to the current state of the Vapory Network, timing deployments can be tricky. Normally results are expected in less than 10 seconds. However, some deployments may take ten minutes as Vapory is just too new. Timing will improve as more nodes come online. Until that growth occurs, the sleep function must be adjusted to avoid the node.js error. If the timing error is encountered, don't fret, the contract is most likely deployed.

Step Five - Confirm your Transaction on Vaporscan

Deploy.js will output a url directing to Vaporscan (https://vaporscan.com) with the corresponding transaction hash. At the time of writing this article, Vaporscan reached an age of one week and does not yet have an intuitive presentation to view and interact with Vapory Smart Contracts. One will need to write the code for that.


Original Link: https://dev.to/marlonhanks/deploying-helloworld-on-vapory-4fia

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To