0.0.8 • Published 4 months ago

@layerzerolabs/scan-client v0.0.8

Weekly downloads
-
License
BUSL-1.1
Repository
-
Last release
4 months ago

Installation

yarn add @layerzerolabs/scan-client

pnpm add @layerzerolabs/scan-client

npm install @layerzerolabs/scan-client

Usage

createClient

import {createClient} from '@layerzerolabs/scan-client';

// Initialize a client with the desired environment
const client = createClient('testnet');

// Get a list of messages by transaction hash
const {messages} = await client.getMessagesBySrcTxHash(
  '0xc6071e98336996084a18a6c47ab38449e31d7d4b48040f35bbcd4106189e3036',
);

// There also is a convenience method that creates the client
// and calls getMessagesBySrcTxHash
import {getMessagesBySrcTxHash} from '@layerzerolabs/scan-client';

const {messages} = getMessagesBySrcTxHash(
  101,
  '0xc6071e98336996084a18a6c47ab38449e31d7d4b48040f35bbcd4106189e3036',
);

// The items in the messages adhere to the following type spec
type Message = {
  srcUaAddress: string;
  dstUaAddress: string;
  srcChainId: number;
  dstChainId: number;
  dstTxHash?: string;
  dstTxError?: string;
  srcTxHash: string;
  srcBlockHash: string;
  srcBlockNumber: string;
  srcUaNonce: number;
  status: MessageStatus;
};

enum MessageStatus {
  INFLIGHT = 'INFLIGHT',
  DELIVERED = 'DELIVERED',
  FAILED = 'FAILED',
  PAYLOAD_STORED = 'PAYLOAD_STORED',
  BLOCKED = 'BLOCKED',
  CONFIRMING = 'CONFIRMING',
}

For new transactions the message list may be empty. Polling should be implemented at the application level since it is app specific. Expect the messages list to be empty for recent transactions, before moving to status INFLIGHT, and finally status DELIVERED.

waitForMessageReceived

We've extracted a common use case for the scan client into the helper waitForMessageReceived. Provide the srcChainId, srcTxHash, and optional pollInterval and receive a promise that resolves when the message status is updated to DELIVERED.

Call signature

function waitForMessageReceived(
  srcChainId: number,
  srcTxHash: string,
  pollInterval = 3000,
): Promise<DeliveredMessage>;

Example usage:

import {waitForMessageReceived} from '@layerzerolabs/scan-client';

...

waitForMessageReceived(srcChainId, receipt.txHash)
  .then((message) => {
    updateTx({
      completed: true,
      confirmation: {
        chainId: message.dstChainId,
        txHash: message.dstTxHash,
      },
    });
  })
  .finally(() => {
    updateBalances();
  });
0.0.8

4 months ago

0.0.7

6 months ago

0.0.6

11 months ago

0.0.1

1 year ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.0-beta.6

2 years ago

0.0.0-beta.5

2 years ago

0.0.0-beta.4

2 years ago

0.0.0-beta.3

2 years ago

0.0.0-beta.2

2 years ago

0.0.0-beta.1

2 years ago

0.0.0-beta.0

2 years ago