Blockchain Module

The blockchain module provides functionalities to access blockchain in your application.

Supported Chains

The below available test network are Sepolia testnets.

base, ethereum, optimism, base-test, ethereum-test, optimism-test

Block

To get a block data from a selected chain, use block:

// Get the latest block
block base,latest;
variable blockData = @@;

// Get a specific block by block number
block base,17829399;
variable blockData = @@;

Chain

To get the id of a chain, use chain:

// Get the Optimisim chain id
chain optimisim;
variable chainId = @@;

Nonce

To get the nonce of a wallet address, use nonce:

// Get the nonce of 0x1f9090aaE28b8a3dCeaDf281B0F12828e676c326 on base
nonce base,0x1f9090aaE28b8a3dCeaDf281B0F12828e676c326;
variable walletNonce = @@;

Balance

To get the balance of a wallet address, use balance:

// Get the balance of 0x1f9090aaE28b8a3dCeaDf281B0F12828e676c326 on base
balance base,0x1f9090aaE28b8a3dCeaDf281B0F12828e676c326;
variable walletBalance = @@;

Ether

To convert wei to ether unit, use ether:

// Convert 1500000000000000000 wei to 1.5 eth
ether 1500000000000000000;
variable weis = @@;

Wei

To convert ether to wei unit, use wei:

// Conver 1.5 eth to 1500000000000000000 wei
wei 1.5;
variable ethers = @@;

Gwei

To convert ether to gwei unit, use gwei:

// Convert 1.5 eth to gwei
gwei 1.5;
variable gweis = @@;

Tx

To get the details of a transaction, use tx:

// Get transaction details of 0xb8bd6c0f5d315d5cc4667238417d5048c87d118c5a75d74f4126b36d580b5f4d on base
tx base, 0xb8bd6c0f5d315d5cc4667238417d5048c87d118c5a75d74f4126b36d580b5f4d;
variable transactionDetails = @@;

Hex

To convert integer to hex, use hex:

// Convert 10 to hex
hex 10;
variable hexed = @@;

Calldata

A serialized transaction payload can be created using calldata.

variable contractAddress = 0x8984bC1b8731C2F73227A2a0f23D1D0Ab0c5A021;
variable walletSignerAddress = 0x1f9090aaE28b8a3dCeaDf281B0F12828e676c326;
variable tokenRecipient = 0x1f67d4047471Aa9371C8AB3757C97eC5Dc5064E7;

// Create call parameters (transfer tokens to tokenRecipient)
variable callParams = {$tokenRecipient},100;

// Create transaction payload
calldata base, {$contractAddress}, transfer, {$callParams};
variable payload = @@;

Questions?

Last updated