CIP 30 - "onAccountChange" and "onNetworkChange" events

In Nami’s former API implementation, a very useful function was implemented to handle user’s account change / network change and I miss it in the current CIP30 standard.

Here is how using it looked like :

await cardano_api.onAccountChange (
    async function (addresses) {
        const b32_addresses = addresses.map (
            function (address) {
                const address_bytes = Buffer.from(address, 'hex');
                return (
                    Loader.Cardano
                            .Address
                            .from_bytes(address_bytes)
                            .to_bech32()
                );
            }
        );
        // ... Do anything with new addresses
        console.log("User account changed :")
        console.log(b32_addresses)
    }
);

Maybe CIP30 standard should include such a function ? CIP1 indicates that I should post here for the proposition to be weighed in by the community.

to broaden the audience for this question can you try creating a cross reference here? (moderators, I don’t think this needs to be be moved since it’s primarily CIP related):

… and keep in mind you can also submit an issue here, but try to get an answer on the Forum first about why this method was dropped:

1 Like

You can register an event callback with the experimental Nami API?

Reference: nami-wallet/injected.js at 259cecff6ebb1c7f8960b740adcca04b14fb840a · Berry-Pool/nami-wallet · GitHub

P.S. something like:

window.cardano.nami.experimental.on(
  'accountChange',
  addresses => { /* do something with addresses */ }
)
1 Like