For AI agents: an LLM-friendly Markdown version of every page is available by appending .md to its URL or by sending an Accept: text/markdown request header. The full documentation index is at https://www.ankr.com/docs/llms.txt
Skip to main content

Avalanche — EVM methods, P-Chain methods (2/2)

API reference for Avalanche. All methods ->

Part 2 of 2: 1 · 2

P-Chain methods

platform.getPendingValidators

Retrieves the list of validators in the pending validator set of the specified Subnet.

Each validator is not currently validating the Subnet but will be doing so in the future.

Parameters

Signature:

platform.getPendingValidators({
subnetID: string, // optional
nodeIDs: string[], // optional
}) -> {
validators: []{
txID: string,
startTime: string,
endTime: string,
stakeAmount: string,
nodeID: string,
delegationFee: string,
connected: bool,
signer: {
publicKey: string,
proofOfPosession: string
},
weight: string,
},
delegators: []{
txID: string,
startTime: string,
endTime: string,
stakeAmount: string,
nodeID: string
}
}

Request parameters:

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (object; required):

    • subnetID: the Subnet whose current validators are returned; if omitted, returns the current validators of the Primary Network.
    • nodeIDs: a list of the NodeIDs of pending validators to request; if omitted, all pending validators are returned; if a specified NodeID is not in the set of pending validators, it will not be included in the response.

Response parameters:

  • validators:
    • txID: the validator transaction.
    • startTime: the Unix time when the validator starts validating the Subnet.
    • endTime: the Unix time when the validator stops validating the Subnet.
    • stakeAmount: the amount of tokens this validator staked. Omitted if subnetID is not a PoS Subnet.
    • nodeID: the validator’s node ID.
    • connected: shows if the node is connected and tracks the Subnet.
    • signer: the node's BLS public key and proof of possession. Omitted if the validator doesn't have a BLS public key.
    • weight the validator’s weight when sampling validators. Omitted if subnetID is a PoS Subnet.
  • delegators:
    • txID: the delegator transaction.
    • startTime: the Unix time when the delegator starts.
    • endTime: the Unix time when the delegator stops.
    • stakeAmount: the amount of tokens this delegator staked.
    • nodeID the validating node’s node ID.

Request example

curl -X POST 'https://rpc.ankr.com/avalanche-p/YOUR_ANKR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"id" :1,
"method" :"platform.getPendingValidators",
"params" :{}
}'

Response example

{
"jsonrpc": "2.0",
"result": {
"validators": [
{
"txID": "2NNkpYTGfTFLSGXJcHtVv6drwVU2cczhmjK2uhvwDyxwsjzZMm",
"startTime": "1600368632",
"endTime": "1602960455",
"stakeAmount": "200000000000",
"nodeID": "NodeID-5mb46qkSBj81k9g9e4VFjGGSbaaSLFRzD",
"delegationFee": "10.0000",
"connected": false
}
],
"delegators": [
{
"txID": "Bbai8nzGVcyn2VmeYcbS74zfjJLjDacGNVuzuvAQkHn1uWfoV",
"startTime": "1600368523",
"endTime": "1602960342",
"stakeAmount": "20000000000",
"nodeID": "NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg"
}
]
},
"id": 1
}

platform.getRewardUTXOs

Retrieves the UTXOs rewarded after the provided transaction's staking or delegation period has ended.

Parameters

Signature:

platform.getRewardUTXOs({
txID: string,
encoding: string // optional
}) -> {
numFetched: integer,
utxos: []string,
encoding: string
}

Request parameters:

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (object; required):

    • txID: the ID of the staking or delegating transaction.

Response parameters:

  • numFetched: the number of returned UTXOs.
  • utxos: an array of encoded reward UTXOs.
  • encoding specifies the format for the returned UTXOs; can only be hex when a value is provided.

Request example

curl -X POST 'https://rpc.ankr.com/avalanche-p/YOUR_ANKR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"id" :1,
"method" :"platform.getRewardUTXOs",
"params" :{
"txID":"2nmH8LithVbdjaXsxVQCQfXtzN9hBbmebrsaEYnLM9T32Uy2Y5",
"encoding": "hex"
}
}'

Response example

{
"jsonrpc": "2.0",
"result": {
"numFetched": "2",
"utxos": [
"0x0000a195046108a85e60f7a864bb567745a37f50c6af282103e47cc62f036cee404700000000345aa98e8a990f4101e2268fab4c4e1f731c8dfbcffa3a77978686e6390d624f000000070000000000000001000000000000000000000001000000018ba98dabaebcd83056799841cfbc567d8b10f216c1f01765",
"0x0000ae8b1b94444eed8de9a81b1222f00f1b4133330add23d8ac288bffa98b85271100000000345aa98e8a990f4101e2268fab4c4e1f731c8dfbcffa3a77978686e6390d624f000000070000000000000001000000000000000000000001000000018ba98dabaebcd83056799841cfbc567d8b10f216473d042a"
],
"encoding": "hex"
},
"id": 1
}

platform.getStake

Retrieves the amount of nAVAX staked by a set of addresses.

The amount returned does not include staking rewards.

Parameters

Signature:

platform.getStake({
addresses: []string,
validatorsOnly: true or false
}) ->
{
stakeds: string -> int,
stakedOutputs: []string,
encoding: string
}

Request parameters:

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (object; required):

    • addresses: the addresses to get information about.
    • validatorsOnly: can be either true or false. If true, will skip checking delegators for stake.

Response parameters:

  • stakeds: a map from assetID to the amount staked by addresses provided.
  • stakedOutputs: the string representation of staked outputs.
  • encoding: specifies the format for the returned outputs.

Request example

curl -X POST 'https://rpc.ankr.com/avalanche-p/YOUR_ANKR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"id" :1,
"method" :"platform.getStake",
"params" :{
"addresses": [
"P-avax1pmgmagjcljjzuz2ve339dx82khm7q8getlegte"
],
"validatorsOnly": true
},
}'

Response example

{
"jsonrpc": "2.0",
"result": {
"staked": "6500000000000",
"stakeds": {
"FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z": "6500000000000"
},
"stakedOutputs": [
"0x000021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff00000007000005e96630e800000000000000000000000001000000011f1c933f38da6ba0ba46f8c1b0a7040a9a991a80dd338ed1"
],
"encoding": "hex"
},
"id": 1
}

platform.getStakingAssetID

Retrieves an assetID for a Subnet’s staking asset.

Parameters

Signature:

platform.getStakingAssetID({
subnetID: string // optional
}) -> {
assetID: string
}

Request parameters:

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (object; required):

    • subnetID: the Subnet whose assetID is requested.

Response parameters:

  • assetID: the assetID for a Subnet’s staking asset.

Request example

curl -X POST 'https://rpc.ankr.com/avalanche-p/YOUR_ANKR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"id" :1,
"method" :"platform.getStakingAssetID",
"params" :{
"subnetID": "11111111111111111111111111111111LpoYY"
},
}'

Response example

{
"jsonrpc": "2.0",
"result": {
"assetID": "2fombhL7aGPwj3KH4bfrmJwW6PVnMobf9Y2fn9GwxiAAJyFDbe"
},
"id": 1
}

platform.getSubnets

Retrieves info about the Subnets.

Parameters

Signature:

platform.getSubnets({
ids: []string
}) ->
{
subnets: []{
id: string,
controlKeys: []string,
threshold: string
}
}

Request parameters:

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (object; required):

    • ids: the IDs of the Subnets to get information about. If omitted, gets information about all Subnets.

Response parameters:

  • subnets:
    • id: the Subnet’s ID.
    • threshold: signatures from addresses in controlKeys are needed to add a validator to the Subnet; if the Subnet is a PoS Subnet, then threshold will be 0 and controlKeys will be empty.

Request example

curl -X POST 'https://rpc.ankr.com/avalanche-p/YOUR_ANKR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"id" :1,
"method" :"platform.getSubnets",
"params" :{
"ids":[
"hW8Ma7dLMA7o4xmJf3AXBbo17bXzE7xnThUd3ypM4VAWo1sNJ"
]
}
}'

Response example

{
"jsonrpc": "2.0",
"result": {
"subnets": [
{
"id": "hW8Ma7dLMA7o4xmJf3AXBbo17bXzE7xnThUd3ypM4VAWo1sNJ",
"controlKeys": [
"KNjXsaA1sZsaKCD1cd85YXauDuxshTes2",
"Aiz4eEt5xv9t4NCnAWaQJFNz5ABqLtJkR"
],
"threshold": "2"
}
]
},
"id": 1
}

platform.getTimestamp

Retrieves the current P-Chain timestamp.

Parameters

Signature:

platform.getTimestamp() -> {time: string}

Request parameters:

  • id (integer; required): a request ID (example: 1).
  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).
  • method (string; required): a method used for the request.
  • params (object; required): None.

Request example

curl -X POST 'https://rpc.ankr.com/avalanche-p/YOUR_ANKR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"id" :1,
"method" :"platform.getTimestamp",
"params" :{}
}'

Response example

{
"jsonrpc": "2.0",
"result": {
"timestamp": "2021-09-07T00:00:00-04:00"
},
"id": 1
}

platform.getTotalStake

Retrieves the total amount of tokens staked on the requested Subnet.

Parameters

Signature:

platform.getTotalStake({
subnetID: string
}) -> {
stake: int
weight: int
}

Request parameters:

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (object; required):

    • subnetID: a string of a Subnet.

Request example (Primary network)

curl -X POST 'https://rpc.ankr.com/avalanche-p/YOUR_ANKR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"id" :1,
"method" :"platform.getTotalStake",
"params" :{
"subnetID": "11111111111111111111111111111111LpoYY"
}
}'

Response example (Primary network)

{
"jsonrpc": "2.0",
"result": {
"stake": "279825917679866811",
"weight": "279825917679866811"
},
"id": 1
}

Request example (Subnet)

curl -X POST 'https://rpc.ankr.com/avalanche-p/YOUR_ANKR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"id" :1,
"method" :"platform.getTotalStake",
"params" :{
"subnetID": "2bRCr6B4MiEfSjidDwxDpdCyviwnfUVqB2HGwhm947w9YYqb7r"
}
}'

Response example (Subnet)

{
"jsonrpc": "2.0",
"result": {
"weight": "100000"
},
"id": 1
}

platform.getTx

Retrieves a transaction by its ID.

Optional encoding parameter to specify the format for the returned transaction. Can be either hex or json. Defaults to hex.

Parameters

Signature:

platform.getTx({
txID: string,
encoding: string // optional
}) -> {
tx: string,
encoding: string,
}

Request parameters:

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (object; required):

    • txID: a string of a transaction ID.

Request example

curl -X POST 'https://rpc.ankr.com/avalanche-p/YOUR_ANKR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"id" :1,
"method" :"platform.getTx",
"params" :{
"txID": "28KVjSw5h3XKGuNpJXWY74EdnGq4TUWvCgEtJPymgQTvudiugb",
"encoding": "json"
}
}'

Response example

{
"jsonrpc": "2.0",
"result": {
"tx": {
"unsignedTx": {
"networkID": 1,
"blockchainID": "11111111111111111111111111111111LpoYY",
"outputs": [],
"inputs": [
{
"txID": "NXNJHKeaJyjjWVSq341t6LGQP5UNz796o1crpHPByv1TKp9ZP",
"outputIndex": 0,
"assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z",
"fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ",
"input": {
"amount": 20824279595,
"signatureIndices": [
0
]
}
},
{
"txID": "2ahK5SzD8iqi5KBqpKfxrnWtrEoVwQCqJsMoB9kvChCaHgAQC9",
"outputIndex": 1,
"assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z",
"fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ",
"input": {
"amount": 28119890783,
"signatureIndices": [
0
]
}
}
],
"memo": "0x",
"validator": {
"nodeID": "NodeID-VT3YhgFaWEzy4Ap937qMeNEDscCammzG",
"start": 1682945406,
"end": 1684155006,
"weight": 48944170378
},
"stake": [
{
"assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z",
"fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ",
"output": {
"addresses": [
"P-avax1tnuesf6cqwnjw7fxjyk7lhch0vhf0v95wj5jvy"
],
"amount": 48944170378,
"locktime": 0,
"threshold": 1
}
}
],
"rewardsOwner": {
"addresses": [
"P-avax19zfygxaf59stehzedhxjesads0p5jdvfeedal0"
],
"locktime": 0,
"threshold": 1
}
},
"credentials": [
{
"signatures": [
"0x6954e90b98437646fde0c1d54c12190fc23ae5e319c4d95dda56b53b4a23e43825251289cdc3728f1f1e0d48eac20e5c8f097baa9b49ea8a3cb6a41bb272d16601"
]
},
{
"signatures": [
"0x6954e90b98437646fde0c1d54c12190fc23ae5e319c4d95dda56b53b4a23e43825251289cdc3728f1f1e0d48eac20e5c8f097baa9b49ea8a3cb6a41bb272d16601"
]
}
],
"id": "28KVjSw5h3XKGuNpJXWY74EdnGq4TUWvCgEtJPymgQTvudiugb"
},
"encoding": "json"
},
"id": 1
}

platform.getTxStatus

Retrieves a transaction’s status by its ID.

If the transaction was dropped, response will include a reason field with more information why the transaction was dropped.

Parameters

Signature:

platform.getTxStatus({
txID: string
}) -> {status: string}

Request parameters:

  • id (integer; required): a request ID (example: 1).

  • jsonrpc (string; required): a JSON RPC spec used (example: 2.0).

  • method (string; required): a method used for the request.

  • params (object; required):

    • txID: a string of a transaction ID.

Response parameters:

  • status: either of the following:
    • Committed: the transaction is (or will be) accepted by every node.
    • Processing: the transaction is being voted on by this node.
    • Dropped: the transaction will never be accepted by any node in the network, check reason field for more information.
    • Unknown: the transaction hasn’t been seen by this node.

Request example

curl -X POST 'https://rpc.ankr.com/avalanche-p/YOUR_ANKR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"id" :1,
"method" :"platform.getTxStatus",
"params" :{
"txID":"TAG9Ns1sa723mZy1GSoGqWipK6Mvpaj7CAswVJGM6MkVJDF9Q"
}
}'

Response example

{
"jsonrpc": "2.0",
"result": {
"status": "Committed"
},
"id": 1
}