diff --git a/README.md b/README.md index a8b2a87..c8fd3bc 100644 --- a/README.md +++ b/README.md @@ -465,6 +465,18 @@ const response: FunctionsResponse = await responseListener.listenForResponseFrom ) ``` +`listenForResponseFromTransaction()` returns a response with the following structure: +``` +{ + requestId: string // Request ID of the fulfilled request represented as a bytes32 hex string + subscriptionId: number // Subscription ID billed for request + totalCostInJuels: bigint // Actual cost of request in Juels (1,000,000,000,000,000,000 (1e18) Juels are equal to 1 LINK) + responseBytesHexstring: string // Response bytes sent to client contract represented as a hex string ("0x" if no response) + errorString: string // Error sent to client contract interpreted as a UTF-8 string ("" if no error) + returnDataBytesHexstring: string // Data returned by consumer contract's handleOracleFulfillment method represented as a hex string + fulfillmentCode: FulfillmentCode // Indicates whether the request was fulfilled successfully or not +} + Alternatively, to listen using a request ID, use the `listenForResponse()` method. **Notes:** diff --git a/src/ResponseListener.ts b/src/ResponseListener.ts index a4456f4..596f359 100644 --- a/src/ResponseListener.ts +++ b/src/ResponseListener.ts @@ -68,7 +68,7 @@ export class ResponseListener { ): Promise { return new Promise((resolve, reject) => { ;(async () => { - let requestID: string + let requestId: string // eslint-disable-next-line prefer-const let checkTimeout: NodeJS.Timeout const expirationTimeout = setTimeout(() => { @@ -77,11 +77,11 @@ export class ResponseListener { const check = async () => { const receipt = await this.provider.waitForTransaction(txHash, confirmations, timeout) - const updatedID = receipt.logs[0].topics[1] - if (updatedID !== requestID) { - requestID = updatedID - const response = await this.listenForResponse(receipt.logs[0].topics[1], timeout) - if (updatedID === requestID) { + const updatedId = receipt.logs[0].topics[1] + if (updatedId !== requestId) { + requestId = updatedId + const response = await this.listenForResponse(requestId, timeout) + if (updatedId === requestId) { // Resolve only if the ID hasn't changed in the meantime clearTimeout(expirationTimeout) clearInterval(checkTimeout)