Integrate Ethereum ERC20 Smart Contract with NodeJS and Web3JS
Ethereum Blockchain, an innovation transformation did you catch wind of this? Take in more about the Ethereum Wallets Blockchain here!
Blockchain is the world’s chief programming stage for advanced resources; it offers the biggest generation square chain stage on the planet. Blockchain, a conveyed database helps in the improvement of a computerized record of exchanges and offer it among a circulating system of PCs conceivable.
Ethereum Wallets is a blockchain-based disseminated processing stage that runs keen contracts. The primary purpose of embracing blockchain innovation is to give a decentralized foundation that is steady and secure for all the including parties.
Ethereum Wallets is a coherent, writable, and programmable record open to any person with an Internet association. A huge number of clients everywhere throughout the world run programming that keeps up the record and these clients are fiscally boosted by the framework itself to do as such.
ERC-20 Protocol
Ethereum Wallet has some official convention for proposing enhancements to Ethereum organize, ERC-20 is one of them.
ERC remains for Ethereum Wallet Request for Comments and ’20’ is the remarkable proposition ID number. Whole ICO industry has developed around ERC-20 tokens; they have assumed a key part of bringing digital currencies into the standard. They have put a bigger effect on the crypto-world.
ERC-20 characterizes an arrangement of tenets which should be met all together for a token to be acknowledged and called as ‘ERC-20 Token’. The standard guidelines apply to all ERC-20 Tokens since these principles are required to communicate with each other on the Ethereum Wallets arrange.
Smart Contracts
Ethereum Wallets in the crypto world is not a substitute to Bitcoin; it is in itself an infrastructure which provides unique options to create decentralized applications (Dapps).
So, how to make these Dapps? To answer this question we need to understand the concept of Smart Contracts.
Smart Contracts are the simplest way to evenly distribute profit shares. It also encourages the trend of accepting cryptocurrencies. Smart contracts offer the technology to evolve to a digital system linking tokens to a real-world asset.
These are robotized contracts. They are self-executing with particular directions composed on its code which get executed when certain conditions are made. As such they are something like a program to keep running on blockchain for a particular reason or important activities.
The reason for executing keen contracts could be more particular as far as assertion between the specialist co-op and the client or any crowdfunding efforts for instance.
Integration with web and Mobile Apps
Blockchain innovation holds the guarantee of altering a significant number of the exchange based procedures that endorse a great part of the worldwide economy. As indicated by an article distributed in Bitcoin Magazine, IDC has evaluated that worldwide spending on blockchain arrangements will achieve a sum of $9.2 billion by 2021. On the off chance that this is valid, their report features that this adds up to a compound yearly development rate of a stunning 81.2%.1
This transformation is disturbing relatively every area. Any site or application that does monetary exchanges regarding enrolment or membership expense, installment against administrations or any gift acknowledgment can be to a great degree profited through this reconciliation.
How this combination really happens? Or on the other hand what all do you have to coordinate your application (web or versatile) with Ethereum, ERC-20 and keen contracts?
You can create wallet address by using Ethereum backed infrastructure, which is based on Amazon Web Services (AWS), by executing your own public or private node or you could pay a small fee and use QuickNode to make it even easier.
The other option is using API, the calls we make are JSON-RPC, not REST to MyEtherWallet to execute your transactions.
Here we take an example of Trust Ethereum Wallets App  it is an Ethereum based app which allows the user to send, receive and store digital assets such as ETH, ETC or ERC 20 tokens.
To integrate your web or mobile apps with Ethereum, smart contracts, you just need two things:
- Ethereum
- Wallet Address
- Code (program) to send and receive tokens
Technically, A blockchain developer can build REST API to connect with Ethereum network, this API could be developed in PHP, NodeJS, JAVA or any other programming language, but generally programmers use mix approach by using NodeJS+Web3JS.
Why is this combination being widely adopted by programmers?
In the latest versions of NodeJS (8 and above) and Web3JS (1.0.0.34 beta or higher) there are various key points to make this combination successful:
- Web3JS libraries are easy to include node_modules & call Ethereum functions
- API is compatible with any programming language
- Supports CURL or JSON RPC call
- Easy to Host in any Dedicated server
- Easy to Test on Test networks rinkeby, Testnet, robsten, etc…
- NodeJS based API is best fit to your business logic
- Stand alone API for Create New wallet address , send / withdrawal , receive / deposit.
- Smart contract tokens
How to use the technology part and how the workflow goes are the next big questions? Here I will try to answer them;
The API calls or JSON RPC calls, while interacting with Ethereum ERC20 Smart Contracts, required passing through following steps:
- Create Ethereum Wallets  Address
- Send ERC20 Tokens to any other ETH wallet address
- Get Balance at Given ETH Wallet address
- SafeLow lowest possible Gas value estimation
- Receiving ERC20 token by simply giving QR Code or ETH wallet address to the sender
Create Ethereum Wallets Address
Ethereum wallets could be made and gotten to at https://www.myetherwallet.com/
MyEtherWallet is an Interface to make a record or ETH wallet address.
To make a record on My Ethereum Wallets you are creating a cryptographic arrangement of numbers: your private key and your open key (address).
The treatment of your keys happens totally on your PC, inside your program.
The server never transmits, get or store your private key, secret word, or other record data. There is no exchange expense for making Ether Wallet Safe .
You are essentially utilizing our interface to collaborate specifically with the blockchain.
Here you can Enter a solid however simple to recall the secret word.
This encodes (secures) your private key. It doesn’t create your private key. This secret word alone will **not** be sufficient to get to your Ether.
Tap the “Make New Ether Paper Wallet”
Download your Keystore/UTC record and spare this document to a USB drive.
This is the scrambled form of your private key. You require the secret word to get to it. It is more secure than your decoded private key yet you must have your secret word to get to it later on.
Read the Caution: Unlock your Ethereum wallets
You should have the private key, keystore JSON or Password to open your ETH wallet deliver to utilize tokens or ETH got. To open your new wallet from the Keystore/UTC document on your USB drive or by means of the private key that you printed out. Guarantee it opens the my ether wallet online you are sent to and coordinates the bookmark you have.
Here are a few alternatives to open your wallet:
After unlocking the wallet, how to use it for sending ERC 20 tokens to any other ETH wallet address.
Send ERC20 Tokens to any other Ethereum wallet address
Sending ERC 20 tokens to any other Ethereum wallets address could be done both Online and offline ways. The process goes through several steps:
Step 1: Generate Information (Online Computer) – Here you need to enter the ‘From Address’ i.e. from where you would like to transfer/send ERC-20 tokens. For example if you want to send some tokens from your own wallet to your friend’s wallet than you need to enter your own wallet address.
Step 2: Generate Transaction (Offline Computer) – Here you need to enter ‘To Address’ i.e. whom you would like to transfer/send ERC-20 tokens. For example your friend’s ETH wallet’s address.
Here you need to enter a few other parameters, such as:
- Value/Amount to Send
- Gas Limit
- Gas Price
- Nonce and Transaction ID or Transaction Hash would be generated as an output parameter.
Step 3: Send/Publish Transaction (Online Computer) – Here you need to enter the transaction ID/ Transaction hash generated at Step 2.
Press Send Transaction button to complete the transaction.
On completion of transaction, now if you want to check the balance of your ETH wallet address or any other Free Ethereum wallet, how you could do that?
JSON :Â {“toaddress”:”0x50d46236b9717a5f8ef52e4c1957d475136A4d90″,”fromaddress”:”0x7c6312dB60499835009bEABbEe1d47CC1e8e9F08″,”amount”:”10″,”privatekey”:”71DAED80385209683B248BCC9835B761D4FD0451A7BF3EB4C7BE8C4328EC537E”,”gas”:”210000″}
Get Balance at Given EThereum Wallets Address
Rest API to Get Balance at Given EThereum Wallet address
JSON :Â Â {“address”:”0x7c6312db60499835009beabbee1d47cc1e8e9f08″}
– You can get total amount ETH or ERC20 Tokens
– You can compare with sending amount + gas must <= total balance
– You can get Balance and Verify with virtual balance in your user DATABASE
What is a virtual balance and why the virtual balance concept is used?
Virtual balance is balance maintained in your MYSQL or MSSQL database, it can be equals to pure balance on EThereum wallets.
Virtual balance is not recommended for Ethereum but in some cases, you can use virtual balance to save total mining cost.
How it is Useful in Saving Total Mining Cost?
If you would like to reward users for login, like, posting content in your social media website, then the virtual balance can save dollars for you.
For an example if you send 1 ERC-20 token at a time, it may cost more gas or mining values to mine a transaction than the actual Transaction amount and as it is mentioned above that the transaction amount must be greater than mining amount.
In such cases, you can reward tokens as virtual balance, simply adding numbers in database but you can send tokens to them when they request you. It actually helps to:
- Save mining cost with effective management and handling transactions.
- Save Token balances in database, so no need to transfer tokens to my Ethewallet safe safe address stored in our database, Saving 1 time mining cost.
- Send Tokens directly to receiving ETH address, saving 2nd time, here you will actually mine transaction so you will spend only one time instead of two.
Now, how to check the estimated Gas Value?
SafeLow Lowest Possible Gas Value Estimation
To get the estimated Gas value you need to follow below process:
REST API for SafeLow lowest possible Gas value estimation
– Input parameters: Amount Ether Paper wallet addresses to find out current gas value
– Output parameters: Total gas value, GWEI, Gas Limit
Conclusion
As a blockchain developer you must explore both programming as well as interface aspect of integrating Ethereum ERC-20 tokens with your website or mobile applications.
Ethereum blockchain is facilitating with an infrastructure to program as well as integrate the ERC-20 tokens and smart contracts with you web or mobile application.
Technically, the programmer must decide on which programming language he would like to work upon. Here in this blog we took an example of working with Web3JS + NodeJS API.
After building and executing the API the Ethereum Wallets could be used to send, receive and store the digital assets. These Ethereum wallet could be easily accessible through the use of internet anywhere around the world.
The Web interface https://www.myetherwallet.com/ allows the user to create a wallet, send/receive ERC-20 tokens, Check balance and transfer virtual balance.
You must remember while dealing with My Ether Wallet:–
- The server do not store any information private or public key
- You have to remember your password/private key to access your funds in Ether wallets address
- If you lose your password or private key , then you will lose tokens because MyEtherWallet will not help to get your funds back without private key or password
Here in this blog we took an example of TrustWalletApp which is an extension of My Free Ethereum Wallet, which is a light client side application that protects early adopters from frustrating token and account management experiences.