Skip to main content

LogsSubscription

LogSubscription to be used to subscribe to events logs.

Following events are supported and can be accessed with either LogsSubscription.once or $LogsSubscription.on methods.

  • connected: Emitted when the subscription is connected.
  • data: Fires on each incoming event with the event object as argument.
  • changed: Fires on each event which was removed from the blockchain. The event will have the additional property removed: true.
  • error: Fires on each error.
const subscription = await myContract.events.MyEvent({
filter: {myIndexedParam: [20,23], myOtherIndexedParam: '0x123456789...'}, // Using an array means OR: e.g. 20 or 23
fromBlock: 0
});

subscription.on("connected", function(subscriptionId){
console.log(subscriptionId);
});

subscription.on('data', function(event){
console.log(event); // same results as the optional callback above
});

subscription.on('changed', function(event){
// remove event from local database
})

subscription.on('error', function(error, receipt) { // If the transaction was rejected by the network with a receipt, the second parameter will be the receipt.
...
});

// event output example
> {
returnValues: {
myIndexedParam: 20,
myOtherIndexedParam: '0x123456789...',
myNonIndexParam: 'My String'
},
raw: {
data: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385',
topics: ['0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385']
},
event: 'MyEvent',
signature: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7',
logIndex: 0,
transactionIndex: 0,
transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385',
blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7',
blockNumber: 1234,
address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'
}

Hierarchy

Index

Constructors

publicconstructor

  • Parameters

    • args: { abi: AbiBaseFragment & { anonymous?: boolean; inputs?: readonly AbiParameter[]; name: string; type: string } & { signature: string }; address?: string; jsonInterface: ContractAbiWithSignature; topics?: (null | string | string[])[] }
    • options: { returnFormat?: DataFormat; subscriptionManager: Web3SubscriptionManager<unknown, {}> }

    Returns LogsSubscription

Properties

publicreadonlyabi

abi: AbiBaseFragment & { anonymous?: boolean; inputs?: readonly AbiParameter[]; name: string; type: string } & { signature: string }

The JSON Interface of the event.

publicoptionalreadonlyaddress

address?: string

Address of tye contract

readonlyargs

args: { abi: AbiEventFragment; address?: string; topics?: (null | string | string[])[] }

Type declaration

  • abi: AbiEventFragment
  • optionaladdress?: string
  • optionaltopics?: (null | string | string[])[]

publicreadonlyjsonInterface

jsonInterface: ContractAbiWithSignature

publicoptionalreadonlytopics

topics?: (null | string | string[])[]

The list of topics subscribed

Accessors

id

  • get id(): undefined | string
  • Returns undefined | string

lastBlock

  • Returns undefined | BlockOutput

Methods

_processSubscriptionError

  • _processSubscriptionError(error: Error): void
  • Parameters

    • error: Error

    Returns void

_processSubscriptionResult

  • _processSubscriptionResult(data: unknown): void
  • Parameters

    • data: unknown

    Returns void

emit

  • emit<K>(eventName: K, params: { changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents[K]): void
  • Type parameters

    • K: Web3EventKey<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents>

    Parameters

    • eventName: K
    • params: { changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents[K]

    Returns void

eventNames

  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

getMaxListeners

  • getMaxListeners(): number
  • Returns number

listenerCount

  • listenerCount<K>(eventName: K): number
  • Type parameters

    • K: Web3EventKey<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents>

    Parameters

    • eventName: K

    Returns number

listeners

  • listeners<K>(eventName: K): (...args: any[]) => void[]
  • Type parameters

    • K: Web3EventKey<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents>

    Parameters

    • eventName: K

    Returns (...args: any[]) => void[]

off

  • off<K>(eventName: K, fn: Web3EventCallback<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents[K]>): void
  • Type parameters

    • K: Web3EventKey<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents>

    Parameters

    • eventName: K
    • fn: Web3EventCallback<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents[K]>

    Returns void

on

  • on<K>(eventName: K, fn: Web3EventCallback<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents[K]>): void
  • Type parameters

    • K: Web3EventKey<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents>

    Parameters

    • eventName: K
    • fn: Web3EventCallback<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents[K]>

    Returns void

once

  • once<K>(eventName: K, fn: Web3EventCallback<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents[K]>): void
  • Type parameters

    • K: Web3EventKey<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents>

    Parameters

    • eventName: K
    • fn: Web3EventCallback<{ changed: EventLog & { removed: true }; data: EventLog } & CommonSubscriptionEvents[K]>

    Returns void

processSubscriptionData

removeAllListeners

  • Returns EventEmitter

resubscribe

  • resubscribe(): Promise<void>
  • Returns Promise<void>

sendSubscriptionRequest

  • sendSubscriptionRequest(): Promise<string>
  • Returns Promise<string>

sendUnsubscribeRequest

  • sendUnsubscribeRequest(): Promise<void>
  • Returns Promise<void>

setMaxListenerWarningThreshold

  • setMaxListenerWarningThreshold(maxListenersWarningThreshold: number): void
  • Parameters

    • maxListenersWarningThreshold: number

    Returns void

subscribe

  • subscribe(): Promise<string>
  • Returns Promise<string>

unsubscribe

  • unsubscribe(): Promise<void>
  • Returns Promise<void>