nexus_getTokenBalance
Get NEP-20 token balance for an address.
Token contract ID (32-byte hex)
Account address (Bitcoin address or hex pubkey)
Token balance information
curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"nexus_getTokenBalance","params":["0x1234...", "bcrt1p..."],"id":1}'
{
"jsonrpc": "2.0",
"result": {
"balance": "0x3b9aca00",
"balanceDecimal": 1000000000
},
"id": 1
}
This endpoint automatically resolves Bitcoin addresses to their internal pubkey representation.
nexus_getTokenHolders
Get all holders of a token.
Token contract ID (32-byte hex)
List of holders with balances
curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"nexus_getTokenHolders","params":["0x1234..."],"id":1}'
{
"jsonrpc": "2.0",
"result": [
{
"address": "0xabcd...",
"balance": "0x3b9aca00"
},
{
"address": "0x5678...",
"balance": "0x1dcd6500"
}
],
"id": 1
}
NEP-20 Standard Functions
NEP-20 tokens implement these standard functions that can be called via nexus_viewCall or nexus_call:
Read Functions (View)
| Function | Arguments | Returns | Description |
|---|
name | none | string | Token name |
symbol | none | string | Token symbol |
decimals | none | u32 | Decimal places |
totalSupply | none | u64 | Total supply |
balanceOf | address | u64 | Balance of address |
allowance | owner, spender | u64 | Spending allowance |
Write Functions (State-Changing)
| Function | Arguments | Returns | Description |
|---|
transfer | to, amount | bool | Transfer tokens |
approve | spender, amount | bool | Approve spending |
transferFrom | from, to, amount | bool | Transfer from approved |
Example: Query Token Info
# Get token name
curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"nexus_viewCall","params":["0x1234...", "name", ""],"id":1}'
# Get token symbol
curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"nexus_viewCall","params":["0x1234...", "symbol", ""],"id":1}'
# Get decimals
curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"nexus_viewCall","params":["0x1234...", "decimals", ""],"id":1}'
Example: Transfer Tokens
Using the SDK:
import { NexusClient, TokenContract } from '@nexus/sdk';
const client = new NexusClient({ rpcUrl: 'http://localhost:8545' }, wallet);
const token = new TokenContract(client, '0x1234...');
// Check balance
const { balanceDecimal } = await token.balanceOf('bcrt1p...');
console.log('Balance:', balanceDecimal);
// Transfer tokens
await token.transfer('bcrt1p...recipient', '1000000');
Using raw RPC:
# Build and sign transfer transaction, then send
curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"nexus_sendRawTransaction","params":["0x...signed_tx..."],"id":1}'
Token Events
NEP-20 tokens emit standard events:
Transfer Event
Emitted on every transfer (including mint/burn).
{
"event_name": "Transfer",
"data": {
"from": "0x...",
"to": "0x...",
"amount": 1000000
}
}
Approval Event
Emitted when allowance is set.
{
"event_name": "Approval",
"data": {
"owner": "0x...",
"spender": "0x...",
"amount": 1000000
}
}
Query Token Events
curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc":"2.0",
"method":"nexus_getEvents",
"params":[{
"contract_id": "0x1234...",
"event_name": "Transfer",
"from_block": 0
}],
"id":1
}'