Indexing Incoming Transaction

The @indexTransaction decorator can be used to mark an indexer method that will be listening for incoming transactions on a contract. Please note that if you are only interested in handling calls to specific entrypoints, @indexEntrypoint is better suited for the job.

When an incoming transaction is detected on an indexed contract, the method will be invoked with detailed information about the call.

Parameters

The following parameters will be passed to the indexing method:

NameDescription

parameter

The parameter object containing:

  • entrypoint property with the name of the entrypoint (string)

  • value with the parameter value (the exact type of the value will depend on the code of the contract)

dbContext

indexingContext

Example

The following code will print the sender and the tokens received on each incoming transaction:

export class MyContractIndexer {
    @indexTransaction()
    indexTransaction(
        parameter: { entrypoint: string; value: unknown },
        dbContext: DbContext,
        indexingContext: TransactionIndexingContext,
    ): void | Promise<void> {
        let op = indexingContext.operationWithResult;
        console.log(`${op.sourceAddress} sent us ${op.amount} mutez`);
    }
}

Last updated