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.
The following parameters will be passed to the indexing method:
Name | Description |
---|---|
parameter | The parameter object containing:
|
dbContext | |
indexingContext |
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 modified 1yr ago