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: https://hive.blog/hiveengine/@fbslo/introducing-wrapped-hive-engine-tokens-wtokens-in-a-box
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...)
- Ethereum address with ~0.1 ETH (price of contract deployment changes based on current gas price)
- Server (I use 4 GB RAM for wHive app, so this server by @privex should be enough, I use Ubuntu 18.04) - for hosting oracle app
- Domain (optional) - for frontend (e.g. https://whive.network)
- CloudFlare (optional) - prevent DDoS attacks
- Infura.io API keys
- Ethplorer.io API keys
- Extended Ethereum private key - https://iancoleman.io/bip39/
- EthGasStation.info API Keys
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!Witness 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.
Interesting behind the scene insight for wrapped tokens creator and some might follow up these step to emerge into the Uniswap world. Liquidity is the secret of our days and getting on Uniswap rather than using a scarcity Hive-Engine can boost any community.
Beside the backend tutorial I would like to see a dummy proof tutorial for a Liquidity Provider starting from the point when a user has some Ethereum on an exchange and what his steps would be to get into the Liquidity Pool, how he can exit and when is better to do so.
Posted Using LeoFinance Beta
Thanks for all the work you're doing to take Hive to the next level.
I gave your witness a vote :)
Posted Using LeoFinance Beta
Thank you very much, I really appreciate it :)
Great work @fbslo! You amaze me every time!!
Cool.
wow, that's a lot to wrap your mind around.
Posted Using LeoFinance Beta
I'm working on solution to make installation super simple, so anyone could create their own wrapped tokens. It should be ready in 1-2 weeks.
Uf, quite a few steps here, I can't handle enough ...
@fbslo,
I wish #HIVE UIs might consider to add download post feature. This is so cool and thank you very much. Will give a try!
$tangent
Cheers~
Thanks, I'm also working on wrappedTokens-in-a-box that will simplify installation from hours of work to one or two commands. It should be ready in 1-2 weeks.
@fbslo,
Wow that's interesting!
Cheers~
Congratulations, @theguruasia You Successfully Trended The Post Shared By @fbslo.
You Utilized 1/3 Daily Summon Bot Calls.
TAN Current Market Price : 0.200 HIVE
Very good work, I even saved your post here for the future because I know I will need to better understand this new universe.
I hope that when wLEO returns I may be able to see something similar in your post. Thank you for sharing knowledge.
Posted Using LeoFinance Beta
Thanks :)
wLEO should be back in 3-6 weeks if everything goes as planned.
!tangent
Congratulations, @asimo You Successfully Trended The Post Shared By @fbslo.
You Utilized 2/3 Daily Summon Bot Calls.
TAN Current Market Price : 0.200 HIVE
Congratulations @fbslo, You Earned 1.358 TAN & Curators Made 1.358 TAN.
Join CORE / VAULT Token Discord Channel or Join UPMELINK Web Site
TAN Current Market Price : 0.200 HIVE
Congratulations @fbslo! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @hivebuzz:
Awesome guide. Thanks for creating this.
ERC-20 Wrapped HIVE tokens are cool..
But I’d LOVE to see SPL HIVE tokens 👀