Skip to main content

nexus_getTokenBalance

Get NEP-20 token balance for an address.
params[0]
string
required
Token contract ID (32-byte hex)
params[1]
string
required
Account address (Bitcoin address or hex pubkey)
result
object
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}'
Response
{
  "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.
params[0]
string
required
Token contract ID (32-byte hex)
result
array
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}'
Response
{
  "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)

FunctionArgumentsReturnsDescription
namenonestringToken name
symbolnonestringToken symbol
decimalsnoneu32Decimal places
totalSupplynoneu64Total supply
balanceOfaddressu64Balance of address
allowanceowner, spenderu64Spending allowance

Write Functions (State-Changing)

FunctionArgumentsReturnsDescription
transferto, amountboolTransfer tokens
approvespender, amountboolApprove spending
transferFromfrom, to, amountboolTransfer 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
  }'