Skip to content
High-level API

High level API for interacting with Phantasma chain

Plain .NET RPC wrapper for the Phantasma API using RpcClient with async / await


Initialization

PhantasmaAPI(string host, RpcClient? rpcClient = null, string? apiKey = null)

Creates a new Phantasma API wrapper using the given RpcClient or a new internal instance

Parameters

  • host: RPC endpoint URL like https://testnet.phantasma.info/rpc
  • rpcClient: optional RpcClient to use. If null, a new instance will be created and disposed by this object
  • apiKey: optional API key sent in the X-Api-Key header on every request. Used only when this wrapper creates its own RpcClient (when rpcClient is null)

Ownership

  • If rpcClient is not provided, the internal client is owned by PhantasmaAPI and will be disposed on Dispose()

Dispose()

Disposes this API instance and the internal RpcClient if owned


Account

Task<AccountInfoResult?> GetAccountInfoAsync(string account)

Gets the account name and staking info of an address

Parameters

  • account: account address text

Returns

  • AccountInfoResult or null if not found

Notes

  • The cost does not depend on how much the address holds, which makes this the call for a wallet refresh loop. Balances and NFTs are read separately through the cursor-paginated account methods.

Task<AccountInfoResult[]?> GetAccountInfosAsync(string[] accounts)

Gets the same record for a batch of up to 100 addresses in one call

Parameters

  • accounts: array of account address texts

Returns

  • array of AccountInfoResult or null

Notes

  • The node answers every address from one state snapshot and returns the records in request order. A malformed address rejects the whole batch.

Task<AccountResult?> GetAccountAsync(string address)

Gets account information, including balances, for the specified address

Parameters

  • address: account address

Returns

  • AccountResult or null if not found

Notes

  • Deprecated. The response embeds every NFT id the address owns, so it grows with the size of the account. The node caps each Balances[].Ids list at 10000 entries while Balances[].Amount keeps the true count, so the list is silently partial for a large holder. Use GetAccountInfoAsync with GetAccountFungibleTokensAsync and GetAccountNFTsAsync.

Task<AccountResult?> GetAccountAsync(string address, bool extended, bool checkAddressReservedByte, RpcAddressType addressType)

Gets account information for a specific address encoding.

Parameters

  • address: account address text
  • extended: deprecated server flag; kept for RPC parity
  • checkAddressReservedByte: true to validate the address reserved byte
  • addressType: account address encoding expected by the RPC

Returns

  • AccountResult or null if not found

Task<AccountResult[]?> GetAccountsAsync(string[] addresses)

Gets account information for multiple addresses

Parameters

  • addresses: array of account addresses

Returns

  • array of AccountResult or null

Notes

  • Deprecated, for the same reason as GetAccountAsync, multiplied by the number of addresses in one call. Use GetAccountInfoAsync.

Task<string?> LookUpNameAsync(string name)

Looks up an address by name

Parameters

  • name: registered name to resolve

Returns

  • resolved address text or null

Task<CursorPaginatedResult<BalanceResult[]>?> GetAccountFungibleTokensAsync(string account, string tokenSymbol = "", ulong carbonTokenId = 0, uint pageSize = 10, string cursor = "", bool checkAddressReservedByte = true)

Gets fungible token balances owned by an address (cursor pagination)

Parameters

  • account: account address
  • tokenSymbol: token symbol filter (optional, cannot be used together with carbonTokenId)
  • carbonTokenId: Carbon token id filter (optional, cannot be used together with tokenSymbol)
  • pageSize: items per page
  • cursor: cursor for the next page
  • checkAddressReservedByte: true to validate address reserved byte

Returns

  • cursor paginated balances or null

Task<CursorPaginatedResult<TokenDataResult[]>?> GetAccountNFTsAsync(string account, string tokenSymbol = "", ulong carbonTokenId = 0, uint carbonSeriesId = 0, uint pageSize = 10, string cursor = "", bool extended = false, bool checkAddressReservedByte = true)

Gets NFTs owned by an address (cursor pagination)

Parameters

  • account: account address
  • tokenSymbol: token symbol filter (optional)
  • carbonTokenId: Carbon token id filter (optional)
  • carbonSeriesId: Carbon series id filter (optional)
  • pageSize: items per page
  • cursor: cursor for the next page
  • extended: true to include properties
  • checkAddressReservedByte: true to validate address reserved byte

Returns

  • cursor paginated NFT data or null

Task<CursorPaginatedResult<TokenResult[]>?> GetAccountOwnedTokensAsync(string account, string tokenSymbol = "", ulong carbonTokenId = 0, uint pageSize = 10, string cursor = "", bool checkAddressReservedByte = true)

Gets NFT tokens for which the account owns at least one NFT instance (cursor pagination)

Parameters

  • account: account address
  • tokenSymbol: token symbol filter (optional)
  • carbonTokenId: Carbon token id filter (optional)
  • pageSize: items per page
  • cursor: cursor for the next page
  • checkAddressReservedByte: true to validate address reserved byte

Returns

  • cursor paginated token data or null

Task<CursorPaginatedResult<TokenSeriesResult[]>?> GetAccountOwnedTokenSeriesAsync(string account, string tokenSymbol = "", ulong carbonTokenId = 0, uint pageSize = 10, string cursor = "", bool checkAddressReservedByte = true)

Gets NFT series for which the account owns at least one NFT instance (cursor pagination)

Parameters

  • account: account address
  • tokenSymbol: token symbol filter (optional)
  • carbonTokenId: Carbon token id filter (optional)
  • pageSize: items per page
  • cursor: cursor for the next page
  • checkAddressReservedByte: true to validate address reserved byte

Returns

  • cursor paginated series data or null

Auction

Task<int> GetAuctionsCountAsync(string chainAddressOrName, string symbol)

Gets the number of auctions currently available in the market contract for a given token

Parameters

  • chainAddressOrName: chain address or name
  • symbol: token symbol

Returns

  • auctions count as integer

Task<(AuctionResult[]? result, uint page, uint total, uint totalPages)> GetAuctionsAsync(string chainAddressOrName, string symbol, uint page, uint pageSize)

Gets all auctions currently available in the market contract for a given token with pagination

Parameters

  • chainAddressOrName: chain address or name
  • symbol: token symbol
  • page: page number starting at 1
  • pageSize: items per page

Returns

  • tuple with results array, current page, total items and total pages

Task<AuctionResult?> GetAuctionAsync(string chainAddressOrName, string symbol, string id)

Gets a single auction by symbol and auction id

Parameters

  • chainAddressOrName: chain address or name
  • symbol: token symbol
  • id: auction id

Returns

  • auction data or null

Block

Task<long> GetBlockHeightAsync(string chain)

Gets the latest block height for a chain

Parameters

  • chain: chain name

Returns

  • block height as long

Task<int> GetBlockTransactionCountByHashAsync(string chainAddressOrName, string blockHash)

Gets the number of transactions in a block by block hash

Parameters

  • chainAddressOrName: chain address or name
  • blockHash: block hash

Returns

  • transaction count

Task<BlockResult?> GetBlockByHashAsync(string blockHash)

Gets a block by its hash

Parameters

  • blockHash: block hash

Returns

  • block data or null

Task<BlockResult?> GetBlockByHeightAsync(string chain, long height)

Gets a block by chain and height

Parameters

  • chain: chain name
  • height: block height

Returns

  • block data or null

Task<BlockResult?> GetLatestBlockAsync(string chain)

Gets the latest block for a chain

Parameters

  • chain: chain name

Returns

  • latest block data or null

Task<TransactionResult?> GetTransactionByBlockHashAndIndexAsync(string chainAddressOrName, string blockHash, int index)

Gets a transaction by chain, block hash, and transaction index.

Parameters

  • chainAddressOrName: chain address or name
  • blockHash: block hash
  • index: transaction index within the block

Returns

  • transaction data or null

Chain

Warning

The node stubs these endpoints: getChains returns an empty array and getChain returns a default ChainResult.

Task<ChainResult[]?> GetChainsAsync()

Gets an array of all chains deployed on Phantasma

Returns

  • array of chains or null

Task<ChainResult?> GetChainAsync(string name = "main", bool extended = true)

Gets chain information by name

Parameters

  • name: chain name
  • extended: true to include extended data

Returns

  • chain data or null

Contract

Task<ContractResult?> GetContractAsync(string contractName)

Gets contract metadata by name from the main chain

Parameters

  • contractName: contract name

Returns

  • contract data or null

Task<ContractResult?> GetContractByAddressAsync(string chainAddressOrName, string contractAddress)

Gets contract metadata by address from a specific chain

Parameters

  • chainAddressOrName: chain address or name
  • contractAddress: contract address

Returns

  • contract data or null

Task<ContractResult[]?> GetContractsAsync()

Gets all contracts deployed on the main chain

Returns

  • array of contracts or null

Leaderboard

Warning

The node stubs getLeaderboard and returns a default LeaderboardResult.

Task<LeaderboardResult?> GetLeaderboardAsync(string name)

Gets a leaderboard by name

Parameters

  • name: leaderboard name

Returns

  • leaderboard data or null

Nexus

Warning

The node stubs getNexus and returns a default NexusResult.

Task<NexusResult?> GetNexusAsync()

Gets nexus metadata including an array of all chains deployed on Phantasma

Returns

  • nexus data or null

Organization

Task<OrganizationResult?> GetOrganizationAsync(string name, bool includeMemberCount = false)

Gets organization data by name.

Parameters

  • name: organization name, for example "masters"
  • includeMemberCount: include the member count (requires a server-side member range scan)

Returns

  • organization data or null

Task<CursorPaginatedResult<OrganizationResult[]>?> GetOrganizationsAsync(uint pageSize = 10, string cursor = "", bool includeMemberCount = false)

Lists organizations deployed on Phantasma using cursor pagination.

Parameters

  • pageSize: items per page
  • cursor: cursor for the next page
  • includeMemberCount: include the member count per organization

Returns

  • cursor-paginated organizations or null

Task<CursorPaginatedResult<OrganizationMemberResult[]>?> GetOrganizationMembersAsync(string name, uint pageSize = 10, string cursor = "", bool includeMemberTime = true)

Lists members of an organization by name using cursor pagination.

Parameters

  • name: organization name
  • pageSize: items per page
  • cursor: cursor for the next page
  • includeMemberTime: include each member’s join timestamp

Returns

  • cursor-paginated organization members or null

Task<OrganizationMemberResult?> GetOrganizationMemberAsync(string name, string address, bool checkAddressReservedByte = true, RpcAddressType addressType = RpcAddressType.Phantasma)

Gets membership status for an address in an organization.

Parameters

  • name: organization name
  • address: address to check
  • checkAddressReservedByte: validate the address reserved byte
  • addressType: address text format

Returns

  • organization member status or null

Token

Task<TokenResult?> GetTokenAsync(string symbol)

Gets token metadata by symbol

Parameters

  • symbol: token symbol

Returns

  • token data or null

Task<TokenResult?> GetTokenAsync(string symbol, bool extended, ulong carbonTokenId)

Gets token metadata by symbol or Carbon token id

Parameters

  • symbol: token symbol (optional when using carbonTokenId)
  • extended: true to include extended data
  • carbonTokenId: Carbon token id (optional when using symbol)

Returns

  • token data or null

Task<TokenResult[]?> GetTokensAsync()

Gets an array of all tokens deployed on Phantasma

Returns

  • array of token metadata or null

Task<TokenResult[]?> GetTokensAsync(bool extended, string? ownerAddress = null)

Gets an array of all tokens deployed on Phantasma with optional owner filtering

Parameters

  • extended: true to include extended data
  • ownerAddress: optional owner address filter

Returns

  • array of token metadata or null

Task<CursorPaginatedResult<TokenSeriesResult[]>?> GetTokenSeriesAsync(string symbol = "", ulong carbonTokenId = 0, uint pageSize = 10, string cursor = "")

Gets token series for a token (cursor pagination)

Parameters

  • symbol: token symbol (optional when using carbonTokenId)
  • carbonTokenId: Carbon token id (optional when using symbol)
  • pageSize: items per page
  • cursor: cursor for the next page

Returns

  • cursor paginated series data or null

Task<TokenSeriesResult?> GetTokenSeriesByIdAsync(string symbol = "", ulong carbonTokenId = 0, string seriesId = "", uint carbonSeriesId = 0)

Gets one token series by Phantasma or Carbon identifiers

Parameters

  • symbol: token symbol (optional when using carbonTokenId)
  • carbonTokenId: Carbon token id (optional when using symbol)
  • seriesId: Phantasma series id (optional when using carbonSeriesId)
  • carbonSeriesId: Carbon series id (optional when using seriesId)

Returns

  • token series data or null

Task<CursorPaginatedResult<TokenDataResult[]>?> GetTokenNFTsAsync(ulong carbonTokenId, uint carbonSeriesId = 0, uint pageSize = 10, string cursor = "", bool extended = false, string seriesId = "")

Gets NFTs for a token (cursor pagination)

Parameters

  • carbonTokenId: Carbon token id
  • carbonSeriesId: Carbon series id filter (optional)
  • pageSize: items per page
  • cursor: cursor for the next page
  • extended: true to include properties
  • seriesId: Phantasma series id filter (optional)

Returns

  • cursor paginated NFT data or null

Task<BalanceResult?> GetTokenBalanceAsync(string address, string symbol, string chain = "main")

Gets the token balance for a given address and token symbol

Parameters

  • address: account address
  • symbol: token symbol
  • chain: chain name, default main

Returns

  • balance data or null

Task<BalanceResult?> GetTokenBalanceAsync(string address, string symbol, string chain, bool checkAddressReservedByte, RpcAddressType addressType)

Gets the token balance for a given address, token symbol, and address encoding.

Parameters

  • address: account address text
  • symbol: token symbol
  • chain: chain name
  • checkAddressReservedByte: true to validate the address reserved byte
  • addressType: account address encoding expected by the RPC

Returns

  • balance data or null

Task<TokenDataResult?> GetTokenDataAsync(string symbol, string tokenId)

Gets token data for a specific token id

Parameters

  • symbol: token symbol
  • tokenId: token id

Returns

  • token data or null

Notes

  • Deprecated. The node serves this as a strict subset of getNFT, with property loading forced off, so GetNFTAsync covers it entirely.

Task<TokenDataResult?> GetNFTAsync(string symbol, string tokenId, bool loadProperties)

Gets NFT data and optionally loads properties

Parameters

  • symbol: NFT symbol
  • tokenId: token id
  • loadProperties: true to load properties

Returns

  • NFT data or null

Task<TokenDataResult[]?> GetNFTsAsync(string symbol, IEnumerable<string> tokenIds, bool extended = false)

Gets NFT data for multiple token ids

Parameters

  • symbol: NFT symbol
  • tokenIds: token ids
  • extended: true to load properties

Returns

  • array of NFT data or null

Transactions

Task<(AccountTransactionsResult? result, uint page, uint totalPages)> GetAddressTransactionsAsync(string address, uint page, uint pageSize)

Gets address transactions with pagination

Parameters

  • address: account address
  • page: page number starting at 1
  • pageSize: items per page

Returns

  • tuple with result object, current page, total pages

Task<int> GetAddressTransactionCountAsync(string address, string chain)

Gets the number of transactions for an address on a chain

Parameters

  • address: account address
  • chain: chain name

Returns

  • total number of transactions

Task<TransactionResult?> GetTransactionAsync(string txHash)

Gets a transaction by its hash if available

Parameters

  • txHash: transaction hash

Returns

  • transaction data or null

Task<string?> SendRawTransactionAsync(string txData)

Broadcasts a transaction in hexadecimal encoding

Parameters

  • txData: hex encoded transaction bytes

Returns

  • transaction hash text or null

Task<string?> SendCarbonTransactionAsync(string txData)

Broadcasts a Carbon transaction in hexadecimal encoding

Parameters

  • txData: hex encoded Carbon transaction bytes

Returns

  • transaction hash text or null

Task<ScriptResult?> InvokeRawScriptAsync(string chain, string scriptData)

Invokes a VM script without state changes and returns its result

Parameters

  • chain: chain name
  • scriptData: hex encoded script bytes

Returns

  • script invocation result or null

Task<string> SendTransactionAsync(TxMsg msg, ITxSigner signer, SendTransactionOptions? options = null, CancellationToken cancellationToken = default)

Plans, pre-flights, signs and broadcasts a Carbon message

Parameters

  • msg: the Carbon message a builder produced
  • signer: one ITxSigner. Overloads take IReadOnlyList<ITxSigner>, one IKeyPair or an IKeyPair[]
  • options: fee-plan options plus Preflight, which defaults to true
  • cancellationToken: cancels the call

Returns

  • transaction hash text

Behavior

  • A message whose maxGas is still zero is planned against this chain’s prices. A message the caller already planned is sent as it is.

  • A token creation is refused when the chain says the symbol is taken, and when the lookup established nothing. The call then throws TransactionPreflightException.

  • Fees And Broadcasting


Task<string?> SignAndSendTransactionAsync(IKeyPair keys, string nexus, byte[] script, string chain, string payload, Func<byte[], byte[], byte[], byte[]>? customSignFunction = null, Timestamp? expiration = null)

Builds, signs and broadcasts a transaction with a UTF8 payload

Parameters

  • keys: key pair used to sign a transaction
  • nexus: nexus name
  • script: transaction script bytes
  • chain: target chain name
  • payload: UTF8 payload string
  • customSignFunction: optional custom signer that receives data, script and payload bytes
  • expiration: moment the transaction stops being admissible; null means TxLimits.DefaultExpiryMs (45 seconds) from now

Returns

  • transaction hash text or null

Exceptions

  • throws Exception when the hash returned by RPC does not match the locally computed hash

Task<string?> SignAndSendTransactionAsync(IKeyPair keys, string nexus, byte[] script, string chain, byte[] payload, Func<byte[], byte[], byte[], byte[]>? customSignFunction = null, Timestamp? expiration = null)

Builds, signs and broadcasts a transaction with a binary payload

Parameters

  • keys: key pair used to sign a transaction
  • nexus: nexus name
  • script: transaction script bytes
  • chain: target chain name
  • payload: binary payload bytes
  • customSignFunction: optional custom signer that receives data, script and payload bytes
  • expiration: moment the transaction stops being admissible; null means TxLimits.DefaultExpiryMs (45 seconds) from now

Returns

  • transaction hash text or null

Behavior

  • Without expiration, the transaction expires TxLimits.DefaultExpiryMs (45 seconds) after it is built, the same lifetime a Carbon message gets. A flow with a person in it, such as a hardware wallet confirmation, should pass an expiration taken from the chain’s window with TxLimits.ExpiryWithin
  • The transaction is signed and sent as hex using SendRawTransactionAsync
  • If the hash returned by RPC differs from the locally computed hash an Exception is thrown

Fees And Gas Configuration

ChainFeePlanner Fees

The fee planner of the chain this client talks to

Notes

  • It reads getGasConfig through this client, caches it for a minute, and prices messages with it. Call it as api.Fees.PlanAsync(msg).

Task<GasConfigResult?> GetGasConfigAsync()

Gets the on-chain gas configuration and the chain parameters fee estimation needs

Returns

  • GasConfigResult or null

Notes

  • The configuration changes only through a governance resolution, so the result is safe to cache.

Task<EstimateTransactionResult?> EstimateTransactionAsync(string txData)

Dry-runs a serialized transaction envelope against current chain state

Parameters

  • txData: the serialized envelope as hex

Returns

  • EstimateTransactionResult or null

Notes

  • Signatures inside the envelope may be zero-filled dummies of the correct length. The simulation skips signature checks, and the dummies keep the exact byte length the bill depends on.
  • A node with the estimate service switched off answers a standard RPC error. The local planner is the fallback.

Task<ulong?> ControlTokenIdAsync()

Gets the gas token’s id, which the pre-flight uses as its control lookup

Returns

  • the token id, or null when this client cannot read the gas configuration

Task<IReadOnlyList<InfusedAsset>> InfusedAssetsAsync(ulong tokenId, ulong instanceId)

Gets what an NFT holds at its own address, in the form the fee planner prices

Parameters

  • tokenId: the Carbon token id
  • instanceId: the Carbon instance id

Returns

  • the list of infused assets, which is empty when the NFT holds nothing

Notes

  • A burn returns every one of these to the burner and pays for each, so a burn cannot be planned without this list.

Storage

Warning

The node stubs the archive endpoints: getArchive returns a default ArchiveResult, writeArchive returns false, and readArchive returns an empty string.

Task<ArchiveResult?> GetArchiveAsync(string hash)

Gets archive metadata by its hash

Parameters

  • hash: archive hash

Returns

  • archive data or null

Task<bool> WriteArchiveAsync(string hash, int blockIndex, byte[] blockContent)

Writes a single archive block

Parameters

  • hash: archive hash
  • blockIndex: block index
  • blockContent: block content bytes

Returns

  • true if the write succeeded

Task<string?> ReadArchiveAsync(string hash, int blockIndex)

Reads a single archive block as a base64 string

Parameters

  • hash: archive hash
  • blockIndex: block index

Returns

  • base64 block content or null

Validation helpers

static bool IsValidPrivateKey(string key)

Validates a WIF-formatted private key string

Parameters

  • key: WIF string

Returns

  • true if the key format looks valid

Heuristics

  • must start with L or K and have length 52