Events
정보
Universal Provider는 Node.js EventEmitter API를 통해 총 2개의 이벤트를 발생합니다.
1. accountsChanged
dapp:accountsChanged이벤트는 체인 내부의 계정 변경이 감지되었을 때 발생합니다. 콜백 함수의 인자로 변경된 계정 주소address와 현재 체인의 이름CHAIN_NAME을CHAIN_NAME:address형태로 반환합니다.
type CHAIN_NAME = 'celestia' | 'celo' | 'cosmos' | 'ethereum' | 'juno' | 'klaytn' | 'near' | 'neon' | 'solana';
window.dapp.on('dapp:accountsChanged', (currentAccount: string) => {
console.log(currentAccount); // near:welldone.testnet
});
2. chainChanged
dapp:chainChanged이벤트는 체인 내부의 네트워크 변경이 감지되었을 때 발생합니다. 콜백 함수의 인자로 변경된 네트워크의 IDnetworkID와 현재 체인의 이름CHAIN_NAME을CHAIN_NAME:networkID형태로 반환합니다.
type CHAIN_NAME = 'celestia' | 'celo' | 'cosmos' | 'ethereum' | 'juno' | 'klaytn' | 'near' | 'neon' | 'solana';
window.dapp.on('dapp:chainChanged', (currentNetwork: string) => {
console.log(currentNetwork); //celo:0xf370
});