Course for request transaction

Learn about the common process for creating and sending transactions using the EQ Hub API.

Before to start

An API Key is required to use the API provided by EQ Hub.

  • For information on how to check the API Key of your project, refer to here.
  • For information on using the API Key when sending requests to the EQ Hub API, refer to here.

Transactions can be sent to the blockchain using the API provided by EQ Hub and the Web3 JavaScript library.
The process below describes the common processes to be performed between the transaction process using a smart contract and the transaction process without using a smart contract.

The common process for sending a transaction is as follows.

  • Inquiring Nonce
  • Searching Gas & Gas price
  • Signing the transaction
  • Sending signed transactions

Inquiring Nonce

🚧

Before performing the steps below, check the pre-conditions.

In order to inquire about Nonce information, the micro chain ID of the corresponding blockchain network is required.
For information on micro-chain information on the network, refer to here.

Nonce information is required to send transactions to the blockchain network. The process of inquiring about nonce information using the EQ Hub API is as follows.

  1. Call API to inquire nonce information. For more information on the API, see here.
  2. The nonce information can be inquired through the API response. Check the nonce of the response.

Searching Gas & Gas price

🚧

Before performing the steps below, check the pre-conditions.

In order to query gas and gas price information, the microchain ID of the corresponding blockchain network is required.
For information on micro-chain information on the network, refer to here.

Gas measurements are required to send transactions to the blockchain network, and gas prices are required to query gas measurements. The process of querying gas price information and gas-measured value information is as follows.

  • Gas price inquiry
    1. Call API to query gas price information. For more information on the API, see here.
    2. Gas price information can be inquired through the API response. Check the gas_price in the response
  • Gas inquiry
    1. Call the API to query the gas measurement value with the gas price information you inquired about. For more information on the API, see here.
    2. Encoded factors may be required in the data area to query gas measurement values. Related information is here.
    3. You can query the gas measurement value through the API response. Check the gas in the response

Signing the transaction

Create a transaction object based on the inquired data, and sign the transaction with your private key.

There are many ways to sign a transaction. The example code below explains how to sign a transaction using web3.js, one of the various Web3 JavaScript libraries.

🚧

Before checking the example code, check the contents below.

Among the data contained in the transaction object of the example code below, data is a value required when a transaction is to be sent using a function defined in a smart contract. If you want to send a transaction that executes a function defined in a smart contract, refer to here.

import Web3 from "web3";
const Web3 = require('web3');
const WEB3 = new Web3()

const privateKey = 'YOUR_PRIVATE_KEY';

const transaction = {
	nonce: "0x3",
	chainId: "2081",
	to: "0x827f92fd506f27f7ba1029f280e12eaa2b362000",
	data: "0x42966c68000000000000000000000000000000000000000000000000000000e8d4a51000",
	gas: "0x2540be401",
	gasPrice: "0x89d3",
	value: "0x56bc75e2d63100000"
}

const {rawTransaction} = await WEB3.eth.accounts.signTransaction(transaction, privateKey)


Sending signed transactions

The process of sending a transaction using the rawTransaction created through the 'Signing a transaction' process is as follows.

  1. Call the API to send the transaction. For more information on the API, see here.
  2. The hash value of the transaction can be known through the API response.

Concluding

Through the above process, we learned about the common process for transaction transmission. The API that sends the transaction returns the hash value (identification value) of the transaction in response. You can search the result of the transaction with the returned hash value.

For information on how to check the transaction result through the transaction hash value, refer to here.