> For the complete documentation index, see [llms.txt](https://docs.ai-gents.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ai-gents.io/aigent_layer/academy/api-sdk.md).

# 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.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
// 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");

```

{% endtab %}

{% tab title="Python" %}

```python
# Import the AIGENT Layer SDK
from aigent_sdk import AigentAPI

# Initialize the API client
api_client = AigentAPI(
    endpoint="https://api.aigent-layer.com",  # Replace with actual API endpoint
    api_key="YOUR_API_KEY"                   # Replace with your API key
)

# Query blockchain for latest block
def get_latest_block():
    block = api_client.get_block("latest")
    print("Latest Block:", block)

# Send a transaction
def send_transaction(from_address, to_address, amount):
    tx_response = api_client.send_transaction(
        from_address=from_address,
        to_address=to_address,
        value=amount,
        private_key="YOUR_PRIVATE_KEY"
    )
    print("Transaction ID:", tx_response["id"])

# Fetch account details
def get_account_details(account_address):
    account = api_client.get_account(account_address)
    print("Account Details:", account)

# Example usage
get_latest_block()
send_transaction("0xSenderAddress", "0xReceiverAddress", 100)
get_account_details("0xAccountAddress")
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
# Import the AIGENT Layer SDK
require 'aigent_sdk'

# Initialize the API client
api_client = AigentSDK::Client.new(
  endpoint: "https://api.aigent-layer.com", # Replace with actual API endpoint
  api_key: "YOUR_API_KEY"                  # Replace with your API key
)

# Query blockchain for latest block
def get_latest_block(api_client)
  block = api_client.get_block("latest")
  puts "Latest Block: #{block}"
end

# Send a transaction
def send_transaction(api_client, from_address, to_address, amount)
  tx_response = api_client.send_transaction(
    from: from_address,
    to: to_address,
    value: amount,
    private_key: "YOUR_PRIVATE_KEY"
  )
  puts "Transaction ID: #{tx_response[:id]}"
end

# Fetch account details
def get_account_details(api_client, account_address)
  account = api_client.get_account(account_address)
  puts "Account Details: #{account}"
end

# Example usage
get_latest_block(api_client)
send_transaction(api_client, "0xSenderAddress", "0xReceiverAddress", 100)
get_account_details(api_client, "0xAccountAddress")
```

{% endtab %}
{% endtabs %}

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ai-gents.io/aigent_layer/academy/api-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
