API Reference

CasperDash injects a global API into websites visited by its users at window.casperDashHelper. This API allows websites to request users' Casper accounts, read data from blockchains the user is connected to, and suggest that the user sign messages and transactions.

Methods

casperDashHelper.requestConnection()

requestConnection: () => Promise<void>;

Requests a connection to the DApp

casperDashHelper.requestSwitchAccount()

requestSwitchAccount: () => Promise<void>;

Requests to switch connected account

casperDashHelper.isConnected()

casperDashHelper.isConnected() : Promise<boolean>;

Returns true if the provider is connected to the current chain, and false otherwise

casperDashHelper.disconnectFromSite()

disconnectFromSite: () => Promise<void>;

Requests a disconnection from the Casper Network DApp

casperDashHelper.signMessage()

signMessage: (message: string, signingPublicKeyHex: string) => Promise<string>;

Suggest that the user sign a message

casperDashHelper.sign()

sign: (deploy: { deploy: JsonTypes }, signingPublicKeyHex: string, targetPublicKey: string) => Promise<Deploy>;

Suggest that the user sign a deploy

casperDashHelper.getActivePublicKey()

getActivePublicKey: () => Promise<string>;

Return the current connected account's public key

Events

connected

window.addEventListener('casperdash:connected', (event: CustomEventInit<{ activeKey: string; isConnected: boolean }>) => {
      console.log({ isConnected: event.detail?.isConnected, activeKey: event.detail?.activeKey });
});

The CasperDash provider emits this event when it first becomes able to submit RPC requests to a chain. We recommend using a connect event handler and the casperDashHelper.isConnected method in order to determine when/if the provider is connected.

disconnected

window.addEventListener('casperdash:disconnected', () => {});

The CasperDash provider emits this event if it becomes unable to submit RPC requests to any chain. In general, this will only happen due to network connectivity issues, some unforeseen error or DApp invokes casperDashHelper.disconnectFromSite() method.

activeKeyChanged

window.addEventListener('casperdash:activeKeyChanged', (event: CustomEventInit<{ activeKey: string; isConnected: boolean }>) => {
      console.log({ isConnected: event.detail?.isConnected, activeKey: event.detail?.activeKey });
});

The CasperDash provider emits this event whenever the return value of the activeKey changes. This means that activeKeyChanged will be emitted whenever the user's exposed account address changes.

Last updated