Guide: Building Transactions with Shibarium RPC Full Nodes

NOWNodes
2 min readNov 29, 2023
New Development Guide — by NOWNodes Tech Team

Let’s #DeployOnShibarium and build the transactions script!

We’re inviting you to our new Shibarium guide on how to utilize specific RPC methods and integrate them into applications or even your own code.

Shibarium Network’s launch granted developers and enterprises with numerous features that make building process easier, faster and more seamless. One of them is having more capacities for scalability: lower gas fees, faster block processing and extremely low latency of network connection points across the globe. Let’s take these advantages and use them in our new guide — How to Build and Send Transactions using Shibarium RPC Methods!

Difficulty Level: Beginner — Middle
Time: From 20–40 min
Prerequisities: Shibarium Wallet, Shibarium RPC Full Node, Programming Environment + Libraries

Step 1 — Preparation

First, install the Web3.js library, which will be used to create, sign, and serialize the transaction.

npm install web3

Then, initialize Web3 and Set Up Your Transaction

const Web3 = require('web3');
const web3 = new Web3('https://shib.nownodes.io');

const tx = {
from: 'YOUR_ADDRESS',
to: 'RECIPIENT_ADDRESS',
value: web3.utils.toWei('AMOUNT', 'ether'),
gas: '21000', // Set the gas limit
gasPrice: web3.utils.toWei('10', 'gwei'), // Set the gas price
nonce: web3.eth.getTransactionCount('YOUR_ADDRESS') // Get the nonce
};

Replace YOUR_ADDRESS, RECIPIENT_ADDRESS, and AMOUNT with the details you have.

Step 2 —Signing and Converting Transaction

Be careful!
This step involves working with Private Keys. Never share it with anyone and do not post your code that can include any of sensible information.

Use your private key to sign the transaction. Ensure this process is done in a secure environment.

const signedTransaction = await web3.eth.accounts.signTransaction(tx, 'YOUR_PRIVATE_KEY');

Once the transaction is signed, you can get the serialized raw transaction in hexadecimal format:

const rawTxHex = signedTransaction.rawTransaction;
console.log(rawTxHex);

rawTxHex will be a string starting with 0x, followed by the hexadecimal representation of the signed transaction.

Step 3 — Working with Shibarium RPC

Now it’s time to work with a specific API method — “eth_sendRawTransaction”. Since you‘ve had the signed transaction in raw format, you can send it to the Shibarium network using, for example, the curl command:

curl --location 'https://shib.nownodes.io' \
--header 'Content-Type: application/json' \
--data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["YOUR_SIGNED_RAW_TRANSACTION"],"id":1}'

Pay attention!
1. Replace YOUR_SIGNED_RAW_TRANSACTION with your signed transaction in raw hex format;
2. Add “api-key” header and use your free API key from NOWNodes or create one at account.nownodes.io.

Here you go!

Two scenarios are possible — the transaction has been successfully sent or an error occured.
In case of any troubles, make sure you’re using right endpoint shib.nownodes.io, the transaction has been converted to the raw format and the script has enough parentheses :)

Explore Shibarium at NOWNodes!

#DeployOnShibarium — we’re here to support you!

--

--