Skip to main content

Watching account

This example connects to aeWallet and watches for updates to the selected account.

tip

Ensure that the aeWallet application is running and unlocked before attempting connection.

info

This snippet uses Javascript language to keep things simple.

But @archethicjs/sdk can be used in a TypeScript or Javascript project.

index.html
<html>
<head>
<script type="module" src="main.js"/>
</head>
</html>
main.js
import Archethic, { ConnectionState } from "https://esm.sh/@archethicjs/sdk";

const archethicClient = new Archethic()


await archethicClient.connect()

/// Listen to rpc wallet connection status changes
const accountSubscription = await archethicClient.rpcWallet.onCurrentAccountChange(async (account) => {
console.log(account)
})

setTimeout(
async () => {

await archethicClient.rpcWallet.close()
archethicClient.rpcWallet.unsubscribe(accountSubscription)
},
20000,
)