P-Chain API
This page is an overview of the P-Chain API associated with AvalancheGo.
The P-Chain API allows clients to interact with the P-Chain, which maintains Avalanche’s validator set and handles blockchain creation.
Endpoint
Format
This API uses the json 2.0
RPC format.
Methods
platform.getBalance
Caution
Deprecated as of v1.9.12.
Get the balance of AVAX controlled by a given address.
Signature:
addresses
are the addresses to get the balance of.balances
is a map from assetID to the total balance.unlockeds
is a map from assetID to the unlocked balance.lockedStakeables
is a map from assetID to the locked stakeable balance.lockedNotStakeables
is a map from assetID to the locked and not stakeable balance.utxoIDs
are the IDs of the UTXOs that referenceaddress
.
Example Call:
Example Response:
platform.getBlock
Get a block by its ID.
Signature:
Request:
blockID
is the block ID. It should be in cb58 format.encoding
is the encoding format to use. Can be eitherhex
orjson
. Defaults tohex
.
Response:
block
is the block encoded toencoding
.encoding
is theencoding
.
Hex Example
Example Call:
Example Response:
JSON Example
Example Call:
Example Response:
platform.getBlockByHeight
Get a block by its height.
Signature:
Request:
height
is the block height.encoding
is the encoding format to use. Can be eitherhex
orjson
. Defaults tohex
.
Response:
block
is the block encoded toencoding
.encoding
is theencoding
.
Hex Example
Example Call:
Example Response:
JSON Example
Example Call:
Example Response:
platform.getBlockchains
Caution
Deprecated as of v1.9.12.
Get all the blockchains that exist (excluding the P-Chain).
Signature:
blockchains
is all of the blockchains that exists on the Avalanche network.name
is the human-readable name of this blockchain.id
is the blockchain’s ID.subnetID
is the ID of the Subnet that validates this blockchain.vmID
is the ID of the Virtual Machine the blockchain runs.
Example Call:
Example Response:
platform.getBlockchainStatus
Get the status of a blockchain.
Signature:
status
is one of:
Validating
: The blockchain is being validated by this node.Created
: The blockchain exists but isn’t being validated by this node.Preferred
: The blockchain was proposed to be created and is likely to be created but the transaction isn’t yet accepted.Syncing
: This node is participating in this blockchain as a non-validating node.Unknown
: The blockchain either wasn’t proposed or the proposal to create it isn’t preferred. The proposal may be resubmitted.
Example Call:
Example Response:
platform.getCurrentSupply
Returns an upper bound on amount of tokens that exist that can stake the requested Subnet. This is an upper bound because it does not account for burnt tokens, including transaction fees.
Signature:
supply
is an upper bound on the number of tokens that exist.
Example Call:
Example Response:
The response in this example indicates that AVAX’s supply is at most 365.865 million.
platform.getCurrentValidators
List the current validators of the given Subnet.
Signature:
subnetID
is the Subnet whose current validators are returned. If omitted, returns the current validators of the Primary Network.nodeIDs
is a list of the NodeIDs of current validators to request. If omitted, all current validators are returned. If a specified NodeID is not in the set of current validators, it will not be included in the response.validators
can include different fields based on the subnet type (L1, PoA Subnets, the Primary Network):txID
is the validator transaction.startTime
is the Unix time when the validator starts validating the Subnet.endTime
is the Unix time when the validator stops validating the Subnet. Ommitted ifsubnetID
is a L1 Subnet.nodeID
is the validator’s node ID.weight
is the validator’s weight (stake) when sampling validators.validationID
is the ID for L1 subnet validator registration transaction. Omitted ifsubnetID
is not an L1 Subnet.publicKey
is the compressed BLS public key of the validator. Omitted ifsubnetID
is not an L1 Subnet.remainingBalanceOwner
is anOutputOwners
which includes alocktime
,threshold
, and an array ofaddresses
. It specifies the owner that will receive any withdrawn balance. Omitted ifsubnetID
is not an L1 Subnet.deactivationOwner
is anOutputOwners
which includes alocktime
,threshold
, and an array ofaddresses
. It specifies the owner that can withdraw the balance. Omitted ifsubnetID
is not an L1 Subnet.minNonce
is minimum nonce that must be included in aSetL1ValidatorWeightTx
for the transaction to be valid. Omitted ifsubnetID
is not an L1 Subnet.balance
is current remaining balance that can be used to pay for the validators continuous fee. Omitted ifsubnetID
is not an L1 Subnet.validationRewardOwner
is anOutputOwners
output which includeslocktime
,threshold
and array ofaddresses
. Specifies the owner of the potential reward earned from staking. Omitted ifsubnetID
is not the Primary Network.delegationRewardOwner
is anOutputOwners
output which includeslocktime
,threshold
and array ofaddresses
. Specifies the owner of the potential reward earned from delegations. Omitted ifsubnetID
is not the Primary Network.potentialReward
is the potential reward earned from staking. Omitted ifsubnetID
is not the Primary Network.delegationFeeRate
is the percent fee this validator charges when others delegate stake to them. Omitted ifsubnetID
is not the Primary Network.uptime
is the % of time the queried node has reported the peer as online and validating the Subnet. Omitted ifsubnetID
is not the Primary Network.connected
is if the node is connected and tracks the Subnet. Omitted ifsubnetID
is not the Primary Network.signer
is the node's BLS public key and proof of possession. Omitted if the validator doesn't have a BLS public key. Omitted ifsubnetID
is not the Primary Network.delegatorCount
is the number of delegators on this validator. Omitted ifsubnetID
is not the Primary Network.delegatorWeight
is total weight of delegators on this validator. Omitted ifsubnetID
is not the Primary Network.delegators
is the list of delegators to this validator. Omitted ifsubnetID
is not the Primary Network. Omitted unlessnodeIDs
specifies a single NodeID.txID
is the delegator transaction.startTime
is the Unix time when the delegator started.endTime
is the Unix time when the delegator stops.weight
is the amount of nAVAX this delegator staked.nodeID
is the validating node’s node ID.rewardOwner
is anOutputOwners
output which includeslocktime
,threshold
and array ofaddresses
.potentialReward
is the potential reward earned from staking
Note: An L1 Subnet can include both initial legacy PoA validators (before L1 conversion) and L1 validators. The response will include both types of validators.
Example Call:
Example Response (Primary Network):
Example Response (L1):
platform.getFeeConfig
Returns the dynamic fee configuration of the P-chain.
Signature:
weights
to merge fee dimensions into a single gas valuemaxCapacity
is the amount of gas the chain is allowed to store for future usemaxPerSecond
is the amount of gas the chain is allowed to consume per secondtargetPerSecond
is the target amount of gas the chain should consume per second to keep fees stableminPrice
is the minimum price per unit of gasexcessConversionConstant
is used to convert excess gas to a gas price
Example Call:
Example Response:
platform.getFeeState
Returns the current fee state of the P-chain.
Signature:
Example Call:
Example Response:
platform.getHeight
Returns the height of the last accepted block.
Signature:
Example Call:
Example Response:
platform.getL1Validator
Returns a current L1 validator.
Signature:
validationID
is the ID for L1 subnet validator registration transaction.subnetID
is the L1 this validator is validating.nodeID
is the node ID of the validator.publicKey
is the compressed BLS public key of the validator.remainingBalanceOwner
is anOutputOwners
which includes alocktime
,threshold
, and an array ofaddresses
. It specifies the owner that will receive any withdrawn balance.deactivationOwner
is anOutputOwners
which includes alocktime
,threshold
, and an array ofaddresses
. It specifies the owner that can withdraw the balance.startTime
is the unix timestamp, in seconds, of when this validator was added to the validator set.weight
is weight of this validator used for consensus voting and ICM.minNonce
is minimum nonce that must be included in aSetL1ValidatorWeightTx
for the transaction to be valid.balance
is current remaining balance that can be used to pay for the validators continuous fee.height
is height of the last accepted block.
Example Call:
Example Response:
platform.getProposedHeight
Returns this node's current proposer VM height
Signature:
Example Call:
Example Response:
platform.getMinStake
Get the minimum amount of tokens required to validate the requested Subnet and the minimum amount of tokens that can be delegated.
Signature:
Example Call:
Example Response:
platform.getRewardUTXOs
Caution
Deprecated as of v1.9.12.
Returns the UTXOs that were rewarded after the provided transaction's staking or delegation period ended.
Signature:
txID
is the ID of the staking or delegating transactionnumFetched
is the number of returned UTXOsutxos
is an array of encoded reward UTXOsencoding
specifies the format for the returned UTXOs. Can only behex
when a value is provided.
Example Call:
Example Response:
platform.getStake
Caution
Deprecated as of v1.9.12.
Get the amount of nAVAX staked by a set of addresses. The amount returned does not include staking rewards.
Signature:
addresses
are the addresses to get information about.validatorsOnly
can be eithertrue
orfalse
. Iftrue
, will skip checking delegators for stake.stakeds
is a map from assetID to the amount staked by addresses provided.stakedOutputs
are the string representation of staked outputs.encoding
specifies the format for the returned outputs.
Example Call:
Example Response:
platform.getStakingAssetID
Retrieve an assetID for a Subnet’s staking asset.
Signature:
subnetID
is the Subnet whose assetID is requested.assetID
is the assetID for a Subnet’s staking asset.
Example Call:
Example Response:
Note
The AssetID for AVAX differs depending on the network you are on.
Mainnet: FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z
Testnet: U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK
platform.getSubnet
Get owners and info about the Subnet or L1.
Signature:
subnetID
is the ID of the Subnet to get information about. If omitted, fails.threshold
signatures from addresses incontrolKeys
are needed to make changes to a permissioned subnet. If the Subnet is not a PoA Subnet, thenthreshold
will be0
andcontrolKeys
will be empty.- changes can not be made into the subnet until
locktime
is in the past. subnetTransformationTxID
is the ID of the transaction that changed the subnet into an elastic one, if it exists.conversionID
is the ID of the conversion from a permissioned Subnet into an L1, if it exists.managerChainID
is the ChainID that has the ability to modify this L1s validator set, if it exists.managerAddress
is the address that has the ability to modify this L1s validator set, if it exists.
Example Call:
Example Response:
platform.getSubnets
Caution
Deprecated as of v1.9.12.
Get info about the Subnets.
Signature:
ids
are the IDs of the Subnets to get information about. If omitted, gets information about all Subnets.id
is the Subnet’s ID.threshold
signatures from addresses incontrolKeys
are needed to add a validator to the Subnet. If the Subnet is not a PoA Subnet, thenthreshold
will be0
andcontrolKeys
will be empty.
See here for information on adding a validator to a Subnet.
Example Call:
Example Response:
platform.getTimestamp
Get the current P-Chain timestamp.
Signature:
Example Call:
Example Response:
platform.getTotalStake
Get the total amount of tokens staked on the requested Subnet.
Signature:
Primary Network Example
Example Call:
Example Response:
Subnet Example
Example Call:
Example Response:
platform.getTx
Gets 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
.
Signature:
Example Call:
Example Response:
platform.getTxStatus
Gets 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.
Signature:
status
is one of:
Committed
: The transaction is (or will be) accepted by every nodeProcessing
: The transaction is being voted on by this nodeDropped
: The transaction will never be accepted by any node in the network, checkreason
field for more informationUnknown
: The transaction hasn’t been seen by this node
Example Call:
Example Response:
platform.getUTXOs
Gets the UTXOs that reference a given set of addresses.
Signature:
utxos
is a list of UTXOs such that each UTXO references at least one address inaddresses
.- At most
limit
UTXOs are returned. Iflimit
is omitted or greater than 1024, it is set to 1024. - This method supports pagination.
endIndex
denotes the last UTXO returned. To get the next set of UTXOs, use the value ofendIndex
asstartIndex
in the next call. - If
startIndex
is omitted, will fetch all UTXOs up tolimit
. - When using pagination (that is when
startIndex
is provided), UTXOs are not guaranteed to be unique across multiple calls. That is, a UTXO may appear in the result of the first call, and then again in the second call. - When using pagination, consistency is not guaranteed across multiple calls. That is, the UTXO set of the addresses may have changed between calls.
encoding
specifies the format for the returned UTXOs. Can only behex
when a value is provided.
Example
Suppose we want all UTXOs that reference at least one of
P-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5
and P-avax1d09qn852zcy03sfc9hay2llmn9hsgnw4tp3dv6
.
This gives response:
Since numFetched
is the same as limit
, we can tell that there may be more UTXOs that were not
fetched. We call the method again, this time with startIndex
:
This gives response:
Since numFetched
is less than limit
, we know that we are done fetching UTXOs and don’t need to
call this method again.
Suppose we want to fetch the UTXOs exported from the X Chain to the P Chain in order to build an
ImportTx. Then we need to call GetUTXOs with the sourceChain
argument in order to retrieve the
atomic UTXOs:
This gives response:
platform.getValidatorsAt
Get the validators and their weights of a Subnet or the Primary Network at a given P-Chain height.
Signature:
height
is the P-Chain height to get the validator set at, or the string literal "proposed" to return the validator set at this node's ProposerVM height.subnetID
is the Subnet ID to get the validator set of. If not given, gets validator set of the Primary Network.
Example Call:
Example Response:
platform.getValidatorFeeConfig
Returns the validator fee configuration of the P-Chain.
Signature:
capacity
is the maximum number of L1 validators the chain is allowed to have at any given timetarget
is the target number of L1 validators the chain should have to keep fees stableminPrice
is the minimum price per L1 validatorexcessConversionConstant
is used to convert excess L1 validators to a gas price
Example Call:
Example Response:
platform.getValidatorFeeState
Returns the current validator fee state of the P-Chain.
Signature:
Example Call:
Example Response:
platform.issueTx
Issue a transaction to the Platform Chain.
Signature:
tx
is the byte representation of a transaction.encoding
specifies the encoding format for the transaction bytes. Can only behex
when a value is provided.txID
is the transaction’s ID.
Example Call:
Example Response:
platform.sampleValidators
Sample validators from the specified Subnet.
Signature:
size
is the number of validators to sample.subnetID
is the Subnet to sampled from. If omitted, defaults to the Primary Network.- Each element of
validators
is the ID of a validator.
Example Call:
Example Response:
platform.validatedBy
Get the Subnet that validates a given blockchain.
Signature:
blockchainID
is the blockchain’s ID.subnetID
is the ID of the Subnet that validates the blockchain.
Example Call:
Example Response:
platform.validates
Get the IDs of the blockchains a Subnet validates.
Signature:
subnetID
is the Subnet’s ID.- Each element of
blockchainIDs
is the ID of a blockchain the Subnet validates.
Example Call:
Example Response: