API/SDK

Connect your applications to AIGENT using powerful APIs.

Example: Query the Blockchain

Retrieve block data with this command:

curl -H "Content-Type: application/json" \
  -X POST \
  --data '{"jsonrpc":"2.0","method":"chain_getBlock","params":[],"id":1}' \
  http://localhost:9933

These examples demonstrate how a user might interact with the AIGENT Layer API for common blockchain-related tasks, such as querying block data, sending transactions, and fetching account details.

// Import the AIGENT Layer SDK
const AigentSDK = require('aigent-sdk');

// Initialize the API client
const apiClient = new AigentSDK({
    endpoint: "https://api.aigent-layer.com", // Replace with actual API endpoint
    apiKey: "YOUR_API_KEY" // Replace with your API key
});

// Query blockchain for latest block
async function getLatestBlock() {
    const block = await apiClient.getBlock("latest");
    console.log("Latest Block:", block);
}

// Send a transaction
async function sendTransaction(from, to, amount) {
    const txResponse = await apiClient.sendTransaction({
        from: from,
        to: to,
        value: amount,
        privateKey: "YOUR_PRIVATE_KEY"
    });
    console.log("Transaction ID:", txResponse.id);
}

// Fetch account details
async function getAccountDetails(accountAddress) {
    const account = await apiClient.getAccount(accountAddress);
    console.log("Account Details:", account);
}

// Example usage
getLatestBlock();
sendTransaction("0xSenderAddress", "0xReceiverAddress", 100);
getAccountDetails("0xAccountAddress");

APIs like this allow seamless integration, letting you access blockchain data and interact with smart contracts easily.

Last updated