Skip to main content

Account Management API events

Account management Snaps can notify MetaMask of the following Account Management API events.

AccountCreated

An account is created. MetaMask returns an error if the account already exists or the account object is invalid.

Example

try {
emitSnapKeyringEvent(snap, KeyringEvent.AccountCreated, { account });
// Update your Snap's state.
} catch (error) {
// Handle the error.
}

AccountUpdated

An account is updated. MetaMask returns an error if one of the following is true:

  • The account does not exist.
  • The account object is invalid.
  • The account address is updated.

Example

try {
emitSnapKeyringEvent(snap, KeyringEvent.AccountUpdated, { account });
// Update your Snap's state.
} catch (error) {
// Handle the error.
}

AccountDeleted

An account is deleted. The delete event is idempotent, so it is safe to emit even if the account does not exist.

Example

try {
emitSnapKeyringEvent(snap, KeyringEvent.AccountDeleted, {
id: account.id,
});
// Update your Snap's state.
} catch (error) {
// Handle the error.
}

RequestApproved

A request is approved. MetaMask returns an error if the request does not exist. This event only applies to Snaps that handle requests asynchronously.

Example

try {
emitSnapKeyringEvent(snap, KeyringEvent.RequestApproved, {
id: request.id,
result,
});
// Update your Snap's state.
} catch (error) {
// Handle the error.
}

RequestRejected

A request is rejected. MetaMask returns an error if the request does not exist. This event only applies to Snaps that handle requests asynchronously.

Example

try {
emitSnapKeyringEvent(snap, KeyringEvent.RequestRejected, {
id: request.id,
});
// Update your Snap's state.
} catch (error) {
// Handle the error.
}