Skip to main content
Version: 23.2.x

Class: PolymeshTransactionBatch<ReturnValue, TransformedReturnValue, Args>

base/PolymeshTransactionBatch.PolymeshTransactionBatch

Wrapper class for a batch of Polymesh Transactions

Type parameters

NameType
ReturnValueReturnValue
TransformedReturnValueReturnValue
Argsextends unknown[][] = unknown[][]

Hierarchy

Properties

blockHash

Optional blockHash: string

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

Inherited from

PolymeshTransactionBase.blockHash

Defined in

base/PolymeshTransactionBase.ts:90


blockNumber

Optional blockNumber: BigNumber

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

Inherited from

PolymeshTransactionBase.blockNumber

Defined in

base/PolymeshTransactionBase.ts:95


error

Optional error: PolymeshError

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

Inherited from

PolymeshTransactionBase.error

Defined in

base/PolymeshTransactionBase.ts:70


receipt

Optional receipt: ISubmittableResult

stores the transaction receipt (if successful)

Inherited from

PolymeshTransactionBase.receipt

Defined in

base/PolymeshTransactionBase.ts:75


status

status: TransactionStatus = TransactionStatus.Idle

current status of the transaction

Inherited from

PolymeshTransactionBase.status

Defined in

base/PolymeshTransactionBase.ts:65


txHash

Optional txHash: string

transaction hash (status: Running, Succeeded, Failed)

Inherited from

PolymeshTransactionBase.txHash

Defined in

base/PolymeshTransactionBase.ts:80


txIndex

Optional txIndex: BigNumber

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

Inherited from

PolymeshTransactionBase.txIndex

Defined in

base/PolymeshTransactionBase.ts:85

Accessors

isSuccess

get isSuccess(): boolean

returns true if transaction has completed successfully

Returns

boolean

Inherited from

PolymeshTransactionBase.isSuccess

Defined in

base/PolymeshTransactionBase.ts:714


result

get result(): TransformedReturnValue

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

Returns

TransformedReturnValue

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!

Inherited from

PolymeshTransactionBase.result

Defined in

base/PolymeshTransactionBase.ts:698


transactions

get transactions(): MapTxData<Args>

transactions in the batch with their respective arguments

Returns

MapTxData<Args>

Defined in

base/PolymeshTransactionBatch.ts:77

Methods

getTotalFees

getTotalFees(): Promise<PayingAccountFees>

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

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

Defined in

base/PolymeshTransactionBase.ts:397


onProcessedByMiddleware

onProcessedByMiddleware(listener): UnsubCallback

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

Parameters

NameTypeDescription
listener(err?: PolymeshError) => voidcallback 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

Defined in

base/PolymeshTransactionBase.ts:437


onStatusChange

onStatusChange(listener): UnsubCallback

Subscribe to status changes

Parameters

NameTypeDescription
listener(transaction: GenericPolymeshTransaction<ReturnValue, TransformedReturnValue>) => voidcallback function that will be called whenever the status changes

Returns

UnsubCallback

unsubscribe function

Inherited from

PolymeshTransactionBase.onStatusChange

Defined in

base/PolymeshTransactionBase.ts:379


run

run(): Promise<TransformedReturnValue>

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

Defined in

base/PolymeshTransactionBase.ts:189


splitTransactions

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

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}`);

Defined in

base/PolymeshTransactionBatch.ts:159


supportsSubsidy

supportsSubsidy(): boolean

Returns

boolean

Note

batches can't be subsidized. If the caller is subsidized, they should use splitTransactions and run each transaction separately

Overrides

PolymeshTransactionBase.supportsSubsidy

Defined in

base/PolymeshTransactionBatch.ts:124