From 9f853d0b1070c6b27f8d5c6c048f71dfb42e6fe7 Mon Sep 17 00:00:00 2001 From: NatSabari Date: Sat, 14 Dec 2024 23:13:12 -0500 Subject: [PATCH] Added token transactions --- api/address/token_transactions.md | 206 ++++++++++++++++++++++++++++++ api/address/xch_transactions.md | 2 +- apisidebars.js | 1 + 3 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 api/address/token_transactions.md diff --git a/api/address/token_transactions.md b/api/address/token_transactions.md new file mode 100644 index 00000000..65244a5b --- /dev/null +++ b/api/address/token_transactions.md @@ -0,0 +1,206 @@ +--- +sidebar_position: 4 +--- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import CodeBlock from '@theme/CodeBlock'; +import ApiCallExample from '@site/src/components/ApiCallExample'; + +# Get Token Transactions + +This endpoint allows you to fetch the token (CAT) transaction history for a given address. + +### Endpoint + + + + +```bash +GET https://api.spacescan.io/address/token-transaction/{address} +``` + + + + +```bash +GET https://api-testnet11.spacescan.io/address/token-transaction/{address} +``` + + + + +### Parameters + +| Parameter | Type | Required | Default | Description | +|-----------|------|----------|---------|-------------| +| address | string | Yes | - | The XCH address to fetch token transactions for | +| count | number | No | 100 | Number of transactions to return per type | +| send_cursor | number | No | null | Pagination cursor for sent transactions | +| received_cursor | number | No | null | Pagination cursor for received transactions | + +:::info Free API +Use `api.spacescan.io` for free tier access. See our [API Plans](https://spacescan.io/apis#plans) for rate limits and features. +::: + +:::tip Pro API +Use `pro-api.spacescan.io` with your API key in the `x-api-key` header. See our [API Plans](https://spacescan.io/apis#plans) for details. + +```bash +curl -X GET "https://pro-api.spacescan.io/address/token-transaction/{address}" \ + -H "x-api-key: YOUR_API_KEY" +``` +::: + +### Live API Test + + + + + 🚀 Test API in Browser + + + + + 🚀 Test API in Browser + + + + +### Request Examples + + + + + + +```bash +# Initial request +curl -X GET "https://api.spacescan.io/address/token-transaction/xch1..." + +# Paginated request for specific transaction types +curl -X GET "https://api.spacescan.io/address/token-transaction/xch1...?send_cursor=100&received_cursor=50" +``` + + + + +```bash +curl -X GET "https://api-testnet11.spacescan.io/address/token-transaction/xch1..." +``` + + + + + + + + +```python +import requests + +address = "xch1..." +url = f"https://api.spacescan.io/address/token-transaction/{address}" + +# Request with parameters +params = { + "count": 50, + "send_cursor": 100, + "received_cursor": 50 +} + +response = requests.get(url, params=params) +data = response.json() +print(data) +``` + + + + +```python +import requests + +address = "xch1..." +url = f"https://api-testnet11.spacescan.io/address/token-transaction/{address}" + +response = requests.get(url) +data = response.json() +print(data) +``` + + + + + + + + +```javascript +const address = "xch1..."; +const url = `https://api.spacescan.io/address/token-transaction/${address}`; + +fetch(url) + .then(response => response.json()) + .then(data => console.log(data)) + .catch(error => console.error('Error:', error)); +``` + + + + +```javascript +const address = "xch1..."; +const url = `https://api-testnet11.spacescan.io/address/token-transaction/${address}`; + +fetch(url) + .then(response => response.json()) + .then(data => console.log(data)) + .catch(error => console.error('Error:', error)); +``` + + + + + + +### Response + + + + + + + + + + +### Response Schema + +| Field | Type | Description | +|-------|------|-------------| +| status | string | Success or failure status | +| send_transactions.transactions | array | List of sent token transactions | +| send_transactions.transactions[].coin_id | string | Unique identifier for the coin | +| send_transactions.transactions[].time | string | ISO timestamp of the transaction | +| send_transactions.transactions[].height | number | Block height of the transaction | +| send_transactions.transactions[].token_amount | number | Amount of tokens transferred | +| send_transactions.transactions[].asset_id | string | The asset ID of the token | +| send_transactions.transactions[].token_id | string | The token ID in tkn format | +| send_transactions.transactions[].to | string | Recipient address | +| send_transactions.transactions[].memo | string[] | Optional memo array | +| send_transactions.next_cursor | number | Cursor for next page of sent transactions | +| send_transactions.total_count | number | Total count of sent transactions | +| received_transactions.transactions | array | List of received token transactions | +| received_transactions.transactions[].coin_id | string | Unique identifier for the coin | +| received_transactions.transactions[].time | string | ISO timestamp of the transaction | +| received_transactions.transactions[].height | number | Block height of the transaction | +| received_transactions.transactions[].token_amount | number | Amount of tokens transferred | +| received_transactions.transactions[].asset_id | string | The asset ID of the token | +| received_transactions.transactions[].token_id | string | The token ID in tkn format | +| received_transactions.transactions[].from | string | Sender address | +| received_transactions.transactions[].memo | string[] | Optional memo array | +| received_transactions.next_cursor | number | Cursor for next page of received transactions | +| received_transactions.total_count | number | Total count of received transactions | + +### Notes +- Each transaction type (sent/received) can be paginated independently +- The token_id is derived from the asset_id using the tkn prefix format \ No newline at end of file diff --git a/api/address/xch_transactions.md b/api/address/xch_transactions.md index d41740b0..c28635be 100644 --- a/api/address/xch_transactions.md +++ b/api/address/xch_transactions.md @@ -6,7 +6,7 @@ import TabItem from '@theme/TabItem'; import CodeBlock from '@theme/CodeBlock'; import ApiCallExample from '@site/src/components/ApiCallExample'; -# Get Address XCH Transactions +# Get XCH Transactions This endpoint allows you to fetch the transaction history for a given XCH address with flexible filtering options for different transaction types. diff --git a/apisidebars.js b/apisidebars.js index 660961b3..762b8e81 100644 --- a/apisidebars.js +++ b/apisidebars.js @@ -27,6 +27,7 @@ const sidebars = { 'address/token_balance', 'address/nft_balance', 'address/xch_transactions', + 'address/token_transactions', ], },