Examples
Code examples for interacting with the Iagon Insight API.
cURL
Get UTXOs by Address
bash
curl -X GET \
"https://api.insight.iagon.io/v1/utxos/address/addr_test1qz..." \
-H "Authorization: Bearer YOUR_API_KEY"Get Balance by Address
bash
curl -X GET \
"https://api.insight.iagon.io/v1/assets/balance/address/addr_test1qz..." \
-H "Authorization: Bearer YOUR_API_KEY"Submit Transaction
bash
curl -X POST \
"https://api.insight.iagon.io/v1/tx/submit" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"tx": "84a400..."}'Node.js (fetch)
Get UTXOs by Address
typescript
const API_KEY = "YOUR_API_KEY";
const BASE_URL = "https://api.insight.iagon.io";
const getUtxosByAddress = async (address: string) => {
const response = await fetch(`${BASE_URL}/v1/utxos/address/${address}`, {
headers: {
Authorization: `Bearer ${API_KEY}`,
},
});
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
return response.json();
};
// Usage
const utxos = await getUtxosByAddress("addr_test1qz...");
console.log(utxos);Get Balance by Address
typescript
const getBalanceByAddress = async (address: string) => {
const response = await fetch(`${BASE_URL}/v1/assets/balance/address/${address}`, {
headers: {
Authorization: `Bearer ${API_KEY}`,
},
});
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
return response.json();
};
// Usage
const balance = await getBalanceByAddress("addr_test1qz...");
console.log(`Lovelace: ${balance.data.lovelace}`);Submit Transaction
typescript
const submitTransaction = async (txCbor: string, skipValidation = false) => {
const response = await fetch(`${BASE_URL}/v1/tx/submit`, {
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
tx: txCbor,
skipValidation,
}),
});
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
return response.json();
};
// Usage
const result = await submitTransaction("84a400...");
console.log(`Transaction hash: ${result.data.txHash}`);Node.js (Axios)
Setup
bash
npm install axiosGet UTXOs by Address
typescript
import axios from "axios";
const API_KEY = "YOUR_API_KEY";
const BASE_URL = "https://api.insight.iagon.io";
const client = axios.create({
baseURL: BASE_URL,
headers: {
Authorization: `Bearer ${API_KEY}`,
},
});
const getUtxosByAddress = async (address: string) => {
const { data } = await client.get(`/v1/utxos/address/${address}`);
return data;
};
// Usage
const utxos = await getUtxosByAddress("addr_test1qz...");
console.log(utxos);Get Balance by Address
typescript
const getBalanceByAddress = async (address: string) => {
const { data } = await client.get(`/v1/assets/balance/address/${address}`);
return data;
};
// Usage
const balance = await getBalanceByAddress("addr_test1qz...");
console.log(`Lovelace: ${balance.data.lovelace}`);Submit Transaction
typescript
const submitTransaction = async (txCbor: string, skipValidation = false) => {
const { data } = await client.post("/v1/tx/submit", {
tx: txCbor,
skipValidation,
});
return data;
};
// Usage
const result = await submitTransaction("84a400...");
console.log(`Transaction hash: ${result.data.txHash}`);Python (requests)
Setup
bash
pip install requestsGet UTXOs by Address
python
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.insight.iagon.io"
headers = {
"Authorization": f"Bearer {API_KEY}"
}
def get_utxos_by_address(address: str):
response = requests.get(
f"{BASE_URL}/v1/utxos/address/{address}",
headers=headers
)
response.raise_for_status()
return response.json()
# Usage
utxos = get_utxos_by_address("addr_test1qz...")
print(utxos)Submit Transaction
python
def submit_transaction(tx_cbor: str, skip_validation: bool = False):
response = requests.post(
f"{BASE_URL}/v1/tx/submit",
headers={**headers, "Content-Type": "application/json"},
json={"tx": tx_cbor, "skipValidation": skip_validation}
)
response.raise_for_status()
return response.json()
# Usage
result = submit_transaction("84a400...")
print(f"Transaction hash: {result['data']['txHash']}")