Events

1. Endless Wallet initialization completion event

The init event is executed after the wallet initialization is completed. For example, the getAccount method needs to be called after the init event is completed.

import { EndLessSDKEvent } from '@endlesslab/endless-web3-sdk';

jssdk.on(EndLessSDKEvent.INIT, async () => {
  const getAccountRes = await jssdk.getAccount();
  if (
    getAccountRes.status === UserResponseStatus.APPROVED &&
    getAccountRes.args.account
  ) {
    // getAccountRes.args.account is the address of the wallet
    conosole.log('getAccountRes =====>', getAccountRes);
  }
});

2. Endless Wallet network change event

Network Change is executed when the user switches networks in the wallet and returns network information.

jssdk.on(EndLessSDKEvent.NETWORK_CHANGE, (networkInfo) => {
  console.log('networkInfo', networkInfo);
});

3. Endless Wallet account change event

Account Change is executed when the user switches the current wallet in the wallet and returns the wallet address.

jssdk.on(EndLessSDKEvent.ACCOUNT_CHANGE, (accountAddress) => {
  console.log('accountChange', accountAddress);
  if (accountAddress.account) {
    setAccountAddress(accountAddress.account);
  }
});

4. Endless Wallet connect event

The connect event is executed when the user links the current dapp in the wallet.

import { EndLessSDKEvent } from '@endlesslab/endless-web3-sdk';

jssdk.on(EndLessSDKEvent.CONNECT, (res) => {
  console.log('connect', res);
});

5. Endless Wallet disconnect event

The disconnect event is executed when the user disconnects from the dapp link in the wallet.

import { EndLessSDKEvent } from '@endlesslab/endless-web3-sdk';

jssdk.on(EndLessSDKEvent.DISCONNECT, (res) => {
  console.log('disconnect', res);
});

6. Endless Wallet open event

The open event is executed when the user open the wallet window in the wallet.

import { EndLessSDKEvent } from '@endlesslab/endless-web3-sdk';

jssdk.on(EndLessSDKEvent.OPEN, () => {
  console.log('wallet opened');
});

7. Endless Wallet close event

The closes event is executed when the user closes the wallet window in the wallet.

import { EndLessSDKEvent } from '@endlesslab/endless-web3-sdk';

jssdk.on(EndLessSDKEvent.CLOSE, () => {
  console.log('wallet closed');
});

Last updated