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 likehttps://testnet.phantasma.info/rpcrpcClient: optionalRpcClientto use. Ifnull, a new instance will be created and disposed by this objectapiKey: optional API key sent in theX-Api-Keyheader on every request. Used only when this wrapper creates its ownRpcClient(whenrpcClientisnull)
Ownership
- If
rpcClientis not provided, the internal client is owned byPhantasmaAPIand will be disposed onDispose()
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
AccountInfoResultornullif 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
AccountInfoResultornull
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
AccountResultornullif 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[].Idslist at 10000 entries whileBalances[].Amountkeeps the true count, so the list is silently partial for a large holder. UseGetAccountInfoAsyncwithGetAccountFungibleTokensAsyncandGetAccountNFTsAsync.
Task<AccountResult?> GetAccountAsync(string address, bool extended, bool checkAddressReservedByte, RpcAddressType addressType)
Gets account information for a specific address encoding.
Parameters
address: account address textextended: deprecated server flag; kept for RPC paritycheckAddressReservedByte:trueto validate the address reserved byteaddressType: account address encoding expected by the RPC
Returns
AccountResultornullif not found
Task<AccountResult[]?> GetAccountsAsync(string[] addresses)
Gets account information for multiple addresses
Parameters
addresses: array of account addresses
Returns
- array of
AccountResultornull
Notes
- Deprecated, for the same reason as
GetAccountAsync, multiplied by the number of addresses in one call. UseGetAccountInfoAsync.
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 addresstokenSymbol: token symbol filter (optional, cannot be used together withcarbonTokenId)carbonTokenId: Carbon token id filter (optional, cannot be used together withtokenSymbol)pageSize: items per pagecursor: cursor for the next pagecheckAddressReservedByte:trueto 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 addresstokenSymbol: token symbol filter (optional)carbonTokenId: Carbon token id filter (optional)carbonSeriesId: Carbon series id filter (optional)pageSize: items per pagecursor: cursor for the next pageextended:trueto include propertiescheckAddressReservedByte:trueto 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 addresstokenSymbol: token symbol filter (optional)carbonTokenId: Carbon token id filter (optional)pageSize: items per pagecursor: cursor for the next pagecheckAddressReservedByte:trueto 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 addresstokenSymbol: token symbol filter (optional)carbonTokenId: Carbon token id filter (optional)pageSize: items per pagecursor: cursor for the next pagecheckAddressReservedByte:trueto 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 namesymbol: 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 namesymbol: token symbolpage: page number starting at 1pageSize: 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 namesymbol: token symbolid: 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 nameblockHash: 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 nameheight: 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 nameblockHash: block hashindex: 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 nameextended:trueto 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 namecontractAddress: 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 pagecursor: cursor for the next pageincludeMemberCount: 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 namepageSize: items per pagecursor: cursor for the next pageincludeMemberTime: 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 nameaddress: address to checkcheckAddressReservedByte: validate the address reserved byteaddressType: 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 usingcarbonTokenId)extended:trueto include extended datacarbonTokenId: Carbon token id (optional when usingsymbol)
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:trueto include extended dataownerAddress: 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 usingcarbonTokenId)carbonTokenId: Carbon token id (optional when usingsymbol)pageSize: items per pagecursor: 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 usingcarbonTokenId)carbonTokenId: Carbon token id (optional when usingsymbol)seriesId: Phantasma series id (optional when usingcarbonSeriesId)carbonSeriesId: Carbon series id (optional when usingseriesId)
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 idcarbonSeriesId: Carbon series id filter (optional)pageSize: items per pagecursor: cursor for the next pageextended:trueto include propertiesseriesId: 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 addresssymbol: token symbolchain: chain name, defaultmain
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 textsymbol: token symbolchain: chain namecheckAddressReservedByte:trueto validate the address reserved byteaddressType: 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 symboltokenId: token id
Returns
- token data or
null
Notes
- Deprecated. The node serves this as a strict subset of
getNFT, with property loading forced off, soGetNFTAsynccovers it entirely.
Task<TokenDataResult?> GetNFTAsync(string symbol, string tokenId, bool loadProperties)
Gets NFT data and optionally loads properties
Parameters
symbol: NFT symboltokenId: token idloadProperties:trueto 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 symboltokenIds: token idsextended:trueto 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 addresspage: page number starting at 1pageSize: 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 addresschain: 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 namescriptData: 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 producedsigner: oneITxSigner. Overloads takeIReadOnlyList<ITxSigner>, oneIKeyPairor anIKeyPair[]options: fee-plan options plusPreflight, which defaults totruecancellationToken: cancels the call
Returns
- transaction hash text
Behavior
A message whose
maxGasis 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.
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 transactionnexus: nexus namescript: transaction script byteschain: target chain namepayload: UTF8 payload stringcustomSignFunction: optional custom signer that receives data, script and payload bytesexpiration: moment the transaction stops being admissible;nullmeansTxLimits.DefaultExpiryMs(45 seconds) from now
Returns
- transaction hash text or
null
Exceptions
- throws
Exceptionwhen 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 transactionnexus: nexus namescript: transaction script byteschain: target chain namepayload: binary payload bytescustomSignFunction: optional custom signer that receives data, script and payload bytesexpiration: moment the transaction stops being admissible;nullmeansTxLimits.DefaultExpiryMs(45 seconds) from now
Returns
- transaction hash text or
null
Behavior
- Without
expiration, the transaction expiresTxLimits.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 withTxLimits.ExpiryWithin - The transaction is signed and sent as hex using
SendRawTransactionAsync - If the hash returned by RPC differs from the locally computed hash an
Exceptionis thrown
Fees And Gas Configuration
ChainFeePlanner Fees
The fee planner of the chain this client talks to
Notes
- It reads
getGasConfigthrough this client, caches it for a minute, and prices messages with it. Call it asapi.Fees.PlanAsync(msg).
Task<GasConfigResult?> GetGasConfigAsync()
Gets the on-chain gas configuration and the chain parameters fee estimation needs
Returns
GasConfigResultornull
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
EstimateTransactionResultornull
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
nullwhen 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 idinstanceId: 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 hashblockIndex: block indexblockContent: block content bytes
Returns
trueif the write succeeded
Task<string?> ReadArchiveAsync(string hash, int blockIndex)
Reads a single archive block as a base64 string
Parameters
hash: archive hashblockIndex: 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
trueif the key format looks valid
Heuristics
- must start with
LorKand have length 52