Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Check links below for the JavaScript SDK:
This guide walks through the process of using web3.js to manually sign and send a transaction to a Harmony network. For this example, we will use Node.js and straightforward JavaScript code.
For this guide we will use Harmony Testnet Network.
Next, we can create a directory to store all our relevant files by running:
And create a simple package.json file:
With the package.json file created, we can then install the web3.js package by executing:
We recommended to use bn.js for format values
To verify the installed version of web3.js, you can use the ls
command:
As of the writing of this guide, the version used was 1.3.0.
For our example, we only need a single JavaScript file (arbitrarily named transaction.js, which you can find here) to create and send the transaction, which we will run using the node
command in the terminal. The script will transfer 1 ONE from the genesis account to another address. For simplicity, the file is divided into three sections: variable definition, create transaction, and deploy transaction.
We need to set a couple of values in the variable definitions:
Create our Web3 constructor (Web3
).
Define the HMY_PRIVATE_KEY
variable as the private key of your ONE wallet, what is used to sign the transactions.
Create a local Web3 instance and set the provider to connect to Testnet Harmony network.
Full code samples can be found here.
Check links below for the Go CLI:
Using web3.js with harmony protocol.
Web3.js is a set of libraries that allow developers to interact with Ethereum nodes using HTTP, IPC or WebSocket protocols. Harmony has an Ethereum-like API available that is fully compatible with Ethereum-style JSON RPC invocations. Therefore, developers can leverage this compatibility and use the web3.js library to interact with a Harmony node as if they were doing so on Ethereum.
To get started with the web3.js library, we first need to install it using the following command:
Once done, the simplest setup to start using the library and its methods is the following:
Depending on which network you want to connect to, you can set the HMY_RPC_URL
to the following values:
For Mainnet:
For Testnet:
In the case that you are interested in a more detailed step-by-step guide, you can go to our specific tutorials on using web3.js on a Harmony:
The steps can also be adapted to deploy on the Harmony Testnet, by using the correct RPC_URL
as mentioned before.
You can use all the library functions described in the official Web3 documentation.
Harmony currently supports JavaScript SDK, Golang CLI, Java SDK and Python SDK
Check links below for the Python SDK:
Check links below for the Java SDK:
Code samples can be found