Posts

How to Create Wrapped Hive Engine Tokens [step-by-step]

avatar of @fbslo
25
@fbslo
·
0 views
·
5 min read

How to Create Wrapped Hive Engine Tokens
[step-by-step]


EDIT: New version of oracle software, intended only for HE tokens was released on 8th November 2020:


Since the launch of wLEO token, there has been quite some interest from different HE tribe leaders to create their own wrapped token. This post is a step-by-step guide on how to do it.

original image source

First, wLEO got hacked and it's still not 100% clear how it happened, so there is still a chance that there a vulnerability in this code. USE ON YOUR OWN RISK!


The code is under GNU GPLv3 license, so you are free to use and modify it without any payment. I do appreciate any tips and witness votes. The Wrapped Hive project was sponsored by @theycallmedan, so go vote @threespeak for witness as well. Also, first wHE token development was paid by @leofinance team, so vote for their witness as well.


What do you need?

  • Basic JS skills (if you modify code yourself)
  • Basic SysAdmin skills (to setup server)
  • Basic understanding of crypto (what are private keys, wallets...)

Don't worry, you will learn how to get all of this. Except for server, domain and eth fees, everything else should have free tier.


API keys

Let's first get all the API keys and other things.

For infura.io, register on their website, create new project, and under "setting", you will see "Project ID" and "Project Secret". You will need only "Project ID".

Ethplorer.io API keys you can get by registering on their website, under "API panel" create a new API key.

Extended private key is used to generate new Ethereum addresses ("Hierarchical Deterministic Wallet"). Go to https://iancoleman.io/bip39/, select "ETH - Ethereum" from "coin" dropdown, click "GENERATE" and store BIP39 Mnemonic generated (you will need it later when burning unwrapped tokens). Then scroll down, under "Derivation Path" -> "BIP44" and store "BIP32 Extended Private Key".

For EthGasStation.info, use https://data.defipulse.com/ to create API key.

Greate, you are now ready to start with the actual setup.


ERC20 contract creation

Create ERC20 token before setting up the server. We will use https://github.com/gochain/web3 CLI.

curl -LSs https://raw.githubusercontent.com/gochain/web3/master/install.sh | sh

web3 start export WEB3_NETWORK=ethereum

Add your Ethereum private keys (for address holding 0.1 ETH)

export WEB3_PRIVATE_KEY=ethpprivatekeygoeshere

Create a contract:

web3 generate contract erc20 --symbol WTOKENSYMBOL --name "Wrapped Token Name" -d number_of_decimals

An example for wHIVE would be web3 generate contract erc20 --symbol WHIVE --name "Wrapped Hive" -d 3.

Build and deploy to mainnet:

web3 contract build WTOKENSYMBOL .sol web3 contract deploy WTOKENSYMBOL .bin

You will receive hash for the transaction and from that transaction, you will be able to see your token's contract address.


Server & Oracle app setup

First, let's update server and install NodeJS & NPM:

sudo apt update curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh sudo bash nodesource_setup.sh sudo apt install nodejs

Verify installation:

node -v

It should output something like v12.17.0, use version 12 or up.

npm -v

Should output something like 6.14.4.


Next, install the MongoDB database.

sudo apt install -y mongodb sudo systemctl status mongodb

You should see

mongodb.service - An object/document-oriented database 
   Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled) 
   Active: active (running) since Sat 2018-05-26 07:48:04 UTC; 2min 17s ago 
     Docs: man:mongod(1) 
 Main PID: 2312 (mongod) 
    Tasks: 23 (limit: 1153) 
   CGroup: /system.slice/mongodb.service 
           └─2312 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf 

Start MondoDB CLI create collections:

mongo use ETH-HIVE db.status.insertOne({ type: "token_nonce", nonce: 1 }) db.status.insertOne({ type: "token_fee", fee: "1" })

Make sure token_nonce is 1 if the address used to call token's smart contract only has 1 transaction. Otherwise, update to actual nonce (the nonce is the number of transactions sent from a given address).


Any dev with some basic JS skills can modify the code to run with any HE token, since it's mostly changing the name of the token. Use weed https://github.com/Wrapped-Hive/oracle/tree/weed) branch as base code.

*I also offer service to modify source code and setup entire server for a small fee of $100 (in HIVE or another crypto).

After you have your code ready, upload it to the server and move to its directory. Let's install all NPM dependencies:

npm install

Now rename config file:

cd config mv config.demo.js config.js

Modify the file and add all the info needed:

nano config.js

var config = { 
  "contractAddress": "contract_address", //your token's contract address (from ERC20 token creation) 
  "ethereumAddress": "minter_address", //eth adddress used to deploy contract and will later mint new tokens 
  "privateKey": "minter_private_key", //eth private key 
  "hiveAccount": "deposit_hive_address", //hive account to hold native tokens 
  "hivePrivateKey": "private-key",  
  "mongodb": "url_for_mongodb", //mongodb endpoint, mongodb://127.0.0.1:27017 
  "ethEndpoint": "infura.com-endpoint", 
  "ethplorer_api": "ethplorer.com-api-key", 
  "xpub": "extended_public_key", //extended private key (it's a mistake in the config, it should be xpriv) 
  "ethgasstation_api": "ethgasstation.com api key", 
  "token_api_url": 'http://api.ethplorer.io/getTokenHistory', 
  "min_amount": 1, 
  "max_amount": -2, //negative to disable 
  "fee_deposit": 5, //fee in % 
  "fee_account": "fee_hive_account", //send fees to this account 
  "fee_account_private_key": '5k...', //not use, ignore 
  "hive_api_nodes": [ 
    "https://api.hive.blog", 
    "https://api.hivekings.com", 
    "https://anyx.io", 
    "https://api.openhive.network" 
  ], 
  "ethereum_config": { 
    "chainId": 3, //3: ropsten, 1: mainnet, 
    "chain": "ropsten", //mainnet... 
    "gasLimit": 100000 
  }, 
  "coingecko_api": "secret" //enable /coingegecko API, no caching for getting data about supply 
} 

Save the file and move back to project directory:

cd ..

Install pm2 for easier management:

npm install pm2 -g

Start the app:

sudo pm2 start index.js --name wtoken

To see logs, run sudo pm2 logs wtoken

Visit http://your_server_IP:8080 to see the frontend. Create the first deposit address (wToken to Token) and then add an index to the MongoDB database.

mongo use ETH-HIVE

db.addresses.createIndex({"address": "text"})

You are now ready to accept first deposits!

If you have any questions or problems with the setup, send me a message: fbslo [Hive witness]#8470


I hope this tutorial was not too hard to understand. If you notice any errors, send me a DM on discord: fbslo [Hive witness]#8470

If you would like to hire me to do this for you, also send me a DM: fbslo [Hive witness]#8470


@fbslo

*If you like my work, please support me by voting for my [Hive Witness](https://hivesigner.com/sign/account-witness-vote?witness=fbslo&approve=1)!
[Witness announcement](/@fbslo/witness-re-announcement)*

*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.