Methods

connect

connect(provider: string, options: any): Promise<AccountType|undefined>

Call the connect() method using a provider name as the first parameter to request a connection using that wallet or login mechanism.

Some providers may need an options argument to indicate the connection behavior requested.

disconnect

 disconnect(fromWallet: string, options?: any): void

Usually you will call signOut() method to close a user session. Use disconnect() when you want to clear the connection between the wallet and your app. Next time the user signs in with that wallet, he'll must gran connection permission again.

Send empty arguments or empty string to disconnect from currently active account. Or call disconnect with a wallet provider key to force the disconnection of a specific wallet.

forgetAccount

forgetAccount(account: AccountType): void

Removes an account from the list of known accounts in CSPR.click. It won’t be returned to the list of known accounts unless it’s connected again using the connect() method.

getAccountIdenticon

typescript getAccountIdenticon(hex: string, size: number = 20): HTMLCanvasElement


This method generates a `<canvas>` HTML element to display the account identicon (aka avatar) of the public key.

It can be used with an account hash to display the hash ('#') symbol instead of a public key identicon.

On React, the `<AccountIdenticon>` component is available to wrap the call to this method.

### getActiveAccount

```typescript
getActiveAccount(): AccountType | null 

Gets the account for the current session (if any). Or undefined if there is no active session.

getActiveAccountAsync

getActiveAccountAsync(options?: GetActiveAccountOptions): Promise<AccountType | null> 

Gets the account for the current session (if any). Returns undefined if there is no active session.

Pass options.withBalance = true to include the balance of the account.

getActivePublicKey

getActivePublicKey(): Promise<string | undefined>

Gets the public key for the current session (if any). Or undefined if no active session.

getProviderInfo

getProviderInfo(provider?: string): Promise<ProviderInfo|undefined>

Returns a ProviderInfo object containing the information of the connected wallet, or the specified in the provider argument. Keep in mind that some information is only available if the wallet is connected (e.g. Version of Ledger can only be recovered if the hardware device is connected).

getSignInOptions

getSignInOptions(refresh: boolean = false): Promise<any>

Returns an object with a list of providers enabled to use in the application and a list of known accounts that can be used to sign in automatically with signInWithAccount().

init

init(options: CsprClickInitOptions): void

Call init to initialize CSPR.click in your web application. This MUST be the first method you call after the downloading of the library.

See CsprClickInitOptions for reference on the options parameter.

isConnected

isConnected(provider: string): Promise<boolean | undefined>

Checks if the provider (not the account) indicated as the first argument is connected to the application. Note this check is independent of whether there's an active account on CSPR.click or not or even if that account belongs to the given provider.

isProviderPresent

isProviderPresent(provider: string): boolean

Checks if the provider indicated as the first argument is enabled in the application and installed (in case it’s a browser extension).

isUnlocked

isUnlocked(provider: string): Promise<boolean | undefined>

Returns true if the provider is unlocked. false if the provider is locked.

This method returns undefined when the provider does not offer this information.

send

send(transaction: string | object, signingPublicKey: string): Promise<SendResult | undefined>

Triggers the mechanisms to request your user to sign a transaction with the active wallet.

When the user approves the signature, CSPR.click sends the transaction to the Casper network. A SendResult object is returned with a deployHash value or an error.

The transaction is a json object (or a string) containing either a Deploy or a TransactionV1. In each case, the corresponding wrapper must be present:

  • Deploy: {"deploy": { "hash": "01....

  • TransactionV1: {"transaction": {"Version1": {"hash": "01....

signingPublicKey MUST be the public key for the active account. Otherwise, this method will return an error.

Example using JS SDK:

/* prepare deploy arguments */
const deploy = DeployUtil.makeDeploy(deployParams, session, payment);
const json = DeployUtil.deployToJson(deploy).deploy as object;
const result = csprclick.send(json, signingKey);

sign

sign(transaction: string | object, signingPublicKey: string): Promise<SignResult | undefined>

Triggers the mechanisms to request your user to sign a transaction with the active wallet.

A SignResult object is returned with the signature value or an error.

The transaction is a json object (or a string) containing either a Deploy or a TransactionV1. In each case, the corresponding wrapper must be present:

  • Deploy: {"deploy": { "hash": "01....

  • TransactionV1: {"transaction": {"Version1": {"hash": "01....

signingPublicKey MUST be the public key for the active account. Otherwise, this method will return an error.

signIn

signIn(): void

Triggers a request to a UI library to show a sign-in dialog.

signInWithAccount

signInWithAccount(account: AccountType): Promise<AccountType | undefined>

Starts a session with the indicated account. This account must be one of the accounts returned in getKnownAccounts or getSignInOptions.

Note that no interaction with the account provider is required to sign-in. CSPR.click will check and restore the connection if needed when there's a transaction or message to sign.

signMessage

signMessage(message: string, signingPublicKey: string): Promise<SignResult|undefined>

Triggers the mechanisms to request your user to sign a text message with the active wallet.

signingPublicKey MUST be the public key for the active account. Otherwise, this method will return an error.

signOut

signOut(): void

Closes an active session in your dApp.

Triggers the csprclick:signed_out event.

switchAccount

switchAccount(withProvider: string | undefined, options?: any): Promise<void>

Call this method to request to the specified wallet to offer the user the selection of a different account. This is valid for providers with its own UI (like browser extenstions).

Call this method without any provider to request CSPR.click UI to show the Switch Account modal window.

Last updated