For the complete documentation index, see llms.txt. This page is also available as Markdown.

Using NodeInterface

Installation and configuration

First, you need to install the libraries for interacting with EMC chain nodes. For example, you can useweb3.jsLibrary:

npm install web3

Then, configure your project to connect the EMC chain nodes:

const Web3 = require('web3'); const web3 = new Web3('https://rpc.emcchain.io'); // Replace with the RPC URL of the EMC chain

Query node information

The following is a sample code for querying basic information about a node:

async function getNodeInfo() {

const nodeInfo = await web3.eth.getNodeInfo();

console.log('Node Info:', nodeInfo);

}

getNodeInfo();

Query block information

The following is sample code to query specific block information:

async function getBlockInfo(blockNumber) {

const blockInfo = await web3.eth.getBlock(blockNumber);

console.log('Block Info:', blockInfo);

}

getBlockInfo(123456); //Replace with actual block number

Query transaction information

The following is sample code to query specific transaction information:

async function getTransactionInfo(txHash) {

const transactionInfo = await web3.eth.getTransaction(txHash);

console.log('Transaction Info:', transactionInfo);

}

getTransactionInfo('0x123...'); // Replace with actual transaction hash

Query account information

The following is sample code to query the balance of a specific account:

async function getAccountBalance(address) {

const balance = await web3.eth.getBalance(address);

console.log('Account Balance:', web3.utils.fromWei(balance, 'ether'), 'EMC');

}

getAccountBalance('0xabc...'); //Replace with actual account address

Interact with contracts

The following is sample code for calling smart contract methods on the chain:

const contractABI = [ /* Contract ABI */ ]; const contractAddress = '0xdef...'; // Replace with the actual contract address const contract = new web3.eth.Contract(contractABI, contractAddress);

async function callContractMethod() {

const result = await contract.methods.yourMethod().call();

console.log('Contract Method Result:', result);

}

callContractMethod();

Last updated