Skip to main content
Version: 31.0.x

Class: PolymeshTransactionBatch<ReturnValue, TransformedReturnValue, Args>

Defined in: src/base/PolymeshTransactionBatch.ts:22

Wrapper class for a batch of Polymesh Transactions

Extends​

Type Parameters​

Type ParameterDefault type

ReturnValue

‐

TransformedReturnValue

ReturnValue

Args extends unknown[][]

unknown[][]

Properties​

blockHash?​

optional blockHash?: string

Defined in: src/base/PolymeshTransactionBase.ts:108

hash of the block where this transaction resides (status: Succeeded, Failed)

Inherited from​

PolymeshTransactionBase.blockHash


blockNumber?​

optional blockNumber?: BigNumber

Defined in: src/base/PolymeshTransactionBase.ts:113

number of the block where this transaction resides (status: Succeeded, Failed)

Inherited from​

PolymeshTransactionBase.blockNumber


error?​

optional error?: PolymeshError

Defined in: src/base/PolymeshTransactionBase.ts:88

stores errors thrown while running the transaction (status: Failed, Aborted)

Inherited from​

PolymeshTransactionBase.error


multiSig​

multiSig: MultiSig | null

Defined in: src/base/PolymeshTransactionBase.ts:121

This will be set if the signingAddress is a MultiSig signer, otherwise null

When set it indicates the transaction will be wrapped as a proposal for the MultiSig, meaning .runAsProposal should be used instead of .run

Inherited from​

PolymeshTransactionBase.multiSig


receipt?​

optional receipt?: ISubmittableResult

Defined in: src/base/PolymeshTransactionBase.ts:93

stores the transaction receipt (if successful)

Inherited from​

PolymeshTransactionBase.receipt


status​

status: TransactionStatus = TransactionStatus.Idle

Defined in: src/base/PolymeshTransactionBase.ts:83

current status of the transaction

Inherited from​

PolymeshTransactionBase.status


txHash?​

optional txHash?: string

Defined in: src/base/PolymeshTransactionBase.ts:98

transaction hash (status: Running, Succeeded, Failed)

Inherited from​

PolymeshTransactionBase.txHash


txIndex?​

optional txIndex?: BigNumber

Defined in: src/base/PolymeshTransactionBase.ts:103

transaction index within its block (status: Succeeded, Failed)

Inherited from​

PolymeshTransactionBase.txIndex

Accessors​

isSuccess​

Get Signature​

get isSuccess(): boolean

Defined in: src/base/PolymeshTransactionBase.ts:963

returns true if transaction has completed successfully

Returns​

boolean

Inherited from​

PolymeshTransactionBase.isSuccess


result​

Get Signature​

get result(): TransformedReturnValue

Defined in: src/base/PolymeshTransactionBase.ts:874

returns the transaction result - this is the same value as the Promise run returns

Note​

it is generally preferable to await the Promise returned by transaction.run() instead of reading this property

Throws​

if the transaction.isSuccess property is false — be sure to check that before accessing!

Returns​

TransformedReturnValue

Inherited from​

PolymeshTransactionBase.result


transactions​

Get Signature​

get transactions(): MapTxData<Args>

Defined in: src/base/PolymeshTransactionBatch.ts:78

transactions in the batch with their respective arguments

Returns​

MapTxData<Args>

Methods​

getTotalFees()​

getTotalFees(asProposal?: boolean): Promise<PayingAccountFees>

Defined in: src/base/PolymeshTransactionBase.ts:597

Retrieve a breakdown of the fees required to run this transaction, as well as the Account responsible for paying them

Parameters​

ParameterTypeDefault valueDescription

asProposal

boolean

true

When true (default), treats the transaction as a MultiSig proposal if the signing account is a MultiSig signer. When false, treats the transaction as a direct transaction from the signing account, ignoring the MultiSig.

Returns​

Promise<PayingAccountFees>

Note​

these values might be inaccurate if the transaction is run at a later time. This can be due to a governance vote or other chain related factors (like modifications to a specific subsidizer relationship or a chain upgrade)

Inherited from​

PolymeshTransactionBase.getTotalFees


onProcessedByMiddleware()​

onProcessedByMiddleware(listener: (err?: PolymeshError) => void): UnsubCallback

Defined in: src/base/PolymeshTransactionBase.ts:637

Subscribe to the results of this transaction being processed by the indexing service (and as such, available to the middleware)

Parameters​

ParameterTypeDescription

listener

(err?: PolymeshError) => void

callback function that will be called whenever the middleware is updated with the latest data. If there is an error (timeout or middleware offline) it will be passed to this callback

Returns​

UnsubCallback

unsubscribe function

Note​

this event will be fired even if the queue fails

Throws​

if the middleware wasn't enabled when instantiating the SDK client

Inherited from​

PolymeshTransactionBase.onProcessedByMiddleware


onStatusChange()​

onStatusChange(listener: (transaction: GenericPolymeshTransaction<ReturnValue, TransformedReturnValue>) => void): UnsubCallback

Defined in: src/base/PolymeshTransactionBase.ts:576

Subscribe to status changes

Parameters​

ParameterTypeDescription

listener

(transaction: GenericPolymeshTransaction<ReturnValue, TransformedReturnValue>) => void

callback function that will be called whenever the status changes

Returns​

UnsubCallback

unsubscribe function

Inherited from​

PolymeshTransactionBase.onStatusChange


run()​

run(): Promise<TransformedReturnValue>

Defined in: src/base/PolymeshTransactionBase.ts:286

Run the transaction, update its status and return a result if applicable. Certain transactions create Entities on the blockchain, and those Entities are returned for convenience. For example, when running a transaction that creates an Asset, the Asset itself is returned

Returns​

Promise<TransformedReturnValue>

Inherited from​

PolymeshTransactionBase.run


runAsProposal()​

runAsProposal(): Promise<MultiSigProposal>

Defined in: src/base/PolymeshTransactionBase.ts:239

Run the transaction as a multiSig proposal

Returns​

Promise<MultiSigProposal>

Inherited from​

PolymeshTransactionBase.runAsProposal


splitTransactions()​

splitTransactions(): (PolymeshTransaction<void, void, unknown[]> | PolymeshTransaction<ReturnValue, TransformedReturnValue, unknown[]>)[]

Defined in: src/base/PolymeshTransactionBatch.ts:204

Splits this batch into its individual transactions to be run separately. This is useful if the caller is being subsidized, since batches cannot be run by subsidized Accounts

Returns​

(PolymeshTransaction<void, void, unknown[]> | PolymeshTransaction<ReturnValue, TransformedReturnValue, unknown[]>)[]

Note​

the transactions returned by this method must be run in the same order they appear in the array to guarantee the same behavior. If run out of order, an error will be thrown. The result that would be obtained by running the batch is returned by running the last transaction in the array

Example​

const createAssetTx = await sdk.assets.createAsset(...);

let ticker: string;

if (isPolymeshTransactionBatch<Asset>(createAssetTx)) {
const transactions = createAssetTx.splitTransactions();

for (let i = 0; i < length; i += 1) {
const result = await transactions[i].run();

if (isAsset(result)) {
({ticker} = result)
}
}
} else {
({ ticker } = await createAssetTx.run());
}

console.log(`New Asset created! Ticker: ${ticker}`);

supportsSubsidy()​

supportsSubsidy(): boolean

Defined in: src/base/PolymeshTransactionBatch.ts:135

Returns​

boolean

Note​

batch can only be subsidized if -

  1. Number of transactions in the batch are not more than 7
  2. Every transaction in the batch can be subsidized

Overrides​

PolymeshTransactionBase.supportsSubsidy


toSignablePayload()​

toSignablePayload(metadata?: Record<string, string>, asProposal?: boolean): Promise<TransactionPayload>

Defined in: src/base/PolymeshTransactionBase.ts:899

Returns a representation intended for offline signers.

Parameters​

ParameterTypeDefault valueDescription

metadata

Record<string, string>

{}

Additional information attached to the payload, such as IDs or memos about the transaction

asProposal

boolean

true

When true (default), treats the transaction as a MultiSig proposal if the signing account is a MultiSig signer. When false, treats the transaction as a direct transaction from the signing account, ignoring the MultiSig.

Returns​

Promise<TransactionPayload>

Note​

Usually .run() should be preferred due to is simplicity.

Note​

When using this method, details like account nonces, and transaction mortality require extra consideration. Generating a payload for offline sign implies asynchronicity. If using this API, be sure each procedure is created with the correct nonce, accounting for in flight transactions, and the lifetime is sufficient.

Inherited from​

PolymeshTransactionBase.toSignablePayload