api.client.Network - PolymeshAssociation/polymesh-sdk GitHub Wiki

@polymeshassociation/polymesh-sdk / api/client/Network

api/client/Network

Classes

Network

Defined in: api/client/Network.ts:56

Handles all Network related functionality, including querying for historical events from middleware

Methods

decodeCall()

decodeCall(hex): object

Defined in: api/client/Network.ts:567

Decode the SCALE-encoded call carried by a revive.ethTransact transaction (or any other Polymesh call), so a dapp can render it next to a wallet's confirmation prompt. Does not fix in-wallet legibility (the wallet still shows raw bytes); it removes the worst of the opacity for a dapp that cares

Parameters
Parameter Type Description
hex `0x${string}` SCALE-encoded call, e.g. transaction.toEthSignablePayload()'s transaction.data
Returns

object

args

args: TransactionArgument[]

humanReadable

humanReadable: AnyJson

tag

tag: TxTag

getEventByIndexedArgs()

getEventByIndexedArgs(opts): Promise<EventIdentifier | null>

Defined in: api/client/Network.ts:235

Retrieve a single event by any of its indexed arguments. Can be filtered using parameters

Parameters
Parameter Type Description
opts { eventArg0?: string; eventArg1?: string; eventArg2?: string; eventId: EventIdEnum; moduleId: ModuleIdEnum; } -
opts.eventArg0? string event parameter value to filter by in position 0
opts.eventArg1? string event parameter value to filter by in position 1
opts.eventArg2? string event parameter value to filter by in position 2
opts.eventId EventIdEnum type of the event to fetch
opts.moduleId ModuleIdEnum type of the module to fetch
Returns

Promise<EventIdentifier | null>

Note

uses the middlewareV2

getEventsByIndexedArgs()

getEventsByIndexedArgs(opts): Promise<EventIdentifier[] | null>

Defined in: api/client/Network.ts:598

Retrieve a list of events. Can be filtered using parameters

Parameters
Parameter Type
opts MiddlewarePaginationOptions & object
Returns

Promise<EventIdentifier[] | null>

Deprecated
Note

uses the middlewareV2

getLatestBlock()

getLatestBlock(): Promise<BigNumber>

Defined in: api/client/Network.ts:74

Retrieve the number of the latest finalized block in the chain

Returns

Promise<BigNumber>

getMiddlewareLag()

getMiddlewareLag(): Promise<BigNumber>

Defined in: api/client/Network.ts:754

Get the number of blocks the middleware needs to process to be synced with chain. The lag can be around somewhere upto 15 blocks, but this can increase if the block size being processed by the Middleware is too large. If the lag is too large, its recommended to check the indexer health to make sure the Middleware is processing the blocks.

Returns

Promise<BigNumber>

Note

uses the middleware V2

getMiddlewareMetadata()

getMiddlewareMetadata(): Promise<MiddlewareMetadata | null>

Defined in: api/client/Network.ts:743

Retrieve middleware metadata. Returns null if middleware is disabled

Returns

Promise<MiddlewareMetadata | null>

Note

uses the middleware V2

getNetworkProperties()

getNetworkProperties(): Promise<NetworkProperties>

Defined in: api/client/Network.ts:95

Retrieve information for the current network

Returns

Promise<NetworkProperties>

getProtocolFees()

getProtocolFees(args): Promise<ProtocolFees[]>

Defined in: api/client/Network.ts:121

Retrieve the protocol fees associated with running specific transactions

Parameters
Parameter Type Description
args { tags: TxTag[]; } -
args.tags TxTag[] list of transaction tags (e.g. [TxTags.asset.CreateAsset, TxTags.asset.RegisterUniqueTicker] or ["asset.createAsset", "asset.registerTicker"])
Returns

Promise<ProtocolFees[]>

getSs58Format()

getSs58Format(): BigNumber

Defined in: api/client/Network.ts:88

Retrieve the chain's SS58 format

Returns

BigNumber

getTotalIssuance()
Call Signature

getTotalIssuance(): Promise<BigNumber>

Defined in: api/client/Network.ts:181

Get the total POLYX in existence

Returns

Promise<BigNumber>

Promise that resolves to the current total issuance

Note

this is every POLYX the chain has issued, not the circulating or staked amount. It is the denominator for a staking ratio, and one of the inputs to Polymesh's inflation curve — see staking.getConstants

Call Signature

getTotalIssuance(callback): Promise<UnsubCallback>

Defined in: api/client/Network.ts:192

Get the total POLYX in existence (with subscription support)

Parameters
Parameter Type Description
callback SubCallback<BigNumber> Callback function that receives issuance updates
Returns

Promise<UnsubCallback>

Promise that resolves to an unsubscribe function

Note

can be subscribed to, if connected to node using a web socket

getTransactionByHash()

getTransactionByHash(opts): Promise<ExtrinsicDataWithFees | null>

Defined in: api/client/Network.ts:648

Retrieve a transaction by hash

Parameters
Parameter Type Description
opts { txHash: string; } -
opts.txHash string hash of the transaction
Returns

Promise<ExtrinsicDataWithFees | null>

Note

uses the middlewareV2

getTreasuryAccount()

getTreasuryAccount(): Account

Defined in: api/client/Network.ts:128

Get the treasury wallet address

Returns

Account

getTreasuryBalance()
Call Signature

getTreasuryBalance(): Promise<BigNumber>

Defined in: api/client/Network.ts:141

Get the Treasury POLYX balance

Returns

Promise<BigNumber>

Promise that resolves to the current Treasury balance

Call Signature

getTreasuryBalance(callback): Promise<UnsubCallback>

Defined in: api/client/Network.ts:152

Get the Treasury POLYX balance (with subscription support)

Parameters
Parameter Type Description
callback SubCallback<BigNumber> Callback function that receives balance updates
Returns

Promise<UnsubCallback>

Promise that resolves to an unsubscribe function

Note

can be subscribed to, if connected to node using a web socket

getVersion()

getVersion(): Promise<string>

Defined in: api/client/Network.ts:81

Fetch the current network version (e.g. 3.1.0)

Returns

Promise<string>

submitEthTransaction()

submitEthTransaction(rawSignedTx, opts?): Promise<SubmissionDetails>

Defined in: api/client/Network.ts:344

Submits a raw, signed Ethereum transaction that carries a Polymesh runtime call through the revive pallet's sentinel address. This is the SDK-broadcast submission step, reused here to unlock Fireblocks / KMS / HSM / air-gapped custody flows for Ethereum-derived Accounts: build the payload via transaction.toEthSignablePayload, sign it externally, and submit the raw signed bytes here

Parameters
Parameter Type Description
rawSignedTx `0x${string}` the raw signed Ethereum transaction, as returned by an EthSigner's signTransaction
opts SubmissionOpts bounds on how long to wait while broadcasting and tracking the transaction. Defaults to waiting indefinitely
Returns

Promise<SubmissionDetails>

Throws

TransactionTimeout if a bound in opts is exceeded. The transaction is not cancelled by this, and can be tracked afterwards with watchTransaction

submitTransaction()

submitTransaction(txPayload, signature, opts?): Promise<SubmissionDetails>

Defined in: api/client/Network.ts:278

Submits a transaction payload with its signature to the chain. signature should be hex encoded

Parameters
Parameter Type Description
txPayload TransactionPayloadInput -
signature string -
opts SubmissionOpts bounds on how long to wait while broadcasting and tracking the transaction. Defaults to waiting indefinitely
Returns

Promise<SubmissionDetails>

Throws

if the signature is not hex encoded

Throws

TransactionTimeout if a bound in opts is exceeded. The transaction is not cancelled by this, and can be tracked afterwards with watchTransaction

supportsConfidentialAssets()

supportsConfidentialAssets(): boolean

Defined in: api/client/Network.ts:771

Returns whether or not the connected chain node as support for confidential assets

Returns

boolean

supportsSubscription()

supportsSubscription(): boolean

Defined in: api/client/Network.ts:787

Returns if functions can be subscribed.

Returns

boolean

true if connected over ws(s)://, otherwise false

transferPolyx()

transferPolyx(args, opts?): Promise<GenericPolymeshTransaction<void, void>>

Defined in: api/client/Network.ts:222

Transfer an amount of POLYX to a specified Account

Parameters
Parameter Type
args TransferPolyxParams
opts? ProcedureOpts
Returns

Promise<GenericPolymeshTransaction<void, void>>

Note

this method is of type ProcedureMethod, which means you can call transferPolyx.checkAuthorization on it to see whether the signing Account and Identity have the required roles and permissions to run it

watchTransaction()

watchTransaction(args): Promise<SubmissionDetails>

Defined in: api/client/Network.ts:378

Track a transaction that has already been broadcast, by its hash, and wait for it to be included in a finalized block

Complements transaction.broadcast and the timeouts on submitTransaction / submitEthTransaction: each of those can leave a transaction in flight but untracked. Since this needs nothing but a hash and a block height, tracking can be picked back up in a later session — after a page reload, for instance, where the original handle no longer exists

Parameters
Parameter Type Description
args { isEthTxHash?: boolean; startingBlock: BigNumber; timeout?: number; txHash: string; } -
args.isEthTxHash? boolean set to true when txHash is an Ethereum transaction hash, i.e. the transaction was broadcast by an Ethereum wallet. Those are carried on chain as an unsigned revive.ethTransact extrinsic, so they are matched by their payload rather than by the extrinsic hash
args.startingBlock BigNumber block height to start searching from. This must be at or before the block the transaction was submitted in, or it will not be found. broadcast returns the correct value to persist
args.timeout? number milliseconds to wait before giving up. Defaults to waiting indefinitely
args.txHash string hash of the transaction to look for
Returns

Promise<SubmissionDetails>

Throws

TransactionTimeout if the transaction is not found in time. It may still be included afterwards — this reports only that the search stopped

⚠️ **GitHub.com Fallback** ⚠️