HomeDocumentationNode Service

Code Examples

Explore code examples for common operations using AllChains Node Service. These examples demonstrate how to interact with various blockchain networks in different programming languages.

Select an Example

Get Latest Block Number

Retrieve the latest block number from the blockchain.

// Get latest block number
const axios = require('axios');

axios({
  method: 'post',
  url: 'https://rpc.AllChains.com/v1/eth',
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': 'your-api-key-here'
  },
  data: {
    jsonrpc: '2.0',
    method: 'eth_blockNumber',
    params: [],
    id: 1
  }
})
.then(response => {
  console.log('Latest block number:', parseInt(response.data.result, 16));
})
.catch(error => {
  console.error('Error:', error);
});

Use Our SDKs

For easier integration, we provide official SDKs for popular programming languages. These libraries handle authentication, error handling, and provide typed interfaces for all AllChains API methods.

JavaScript SDK Example

// Using our official SDK
const AllChains = require('AllChains-js');

// Initialize client with your API key
const client = new AllChains('your-api-key-here');

// Get latest Ethereum block number
client.ethereum.getBlockNumber()
  .then(blockNumber => {
    console.log('Latest block number:', blockNumber);
  })
  .catch(error => {
    console.error('Error:', error);
  });

Need Help?

If you need help with your code or have questions about the API, contact our support team or visit our community forum.