Skip to content
Embedded Wallet
API Reference

API Reference

You will find the available methods and their usage in this section

Constructor

new SimpleCryptoSDK(options: InitOptions);

Supported Blockchains

💡

Currenly only Polygon is supported

Additional blockchains coming soon. If you'd like to see support for a particular chain, reach out to shekar@simplecrypto.dev.

InitOptions

ParameterTypeDescription
siteIconstring?A url to your site’s icon that we'll will display in Simple Crypto’s interface. This defaults to your sites favicon if you don’t provide another here.
siteTitlestring?Your site’s title to be displayed within Simple Crypto’s interface. This defaults to your site’s title if it is not explicitly provided here.
themeTheme?The these options used to customize the Simple Crypto UI.

Theme

type Theme = {
    // The primary color Simple Crypto will use in its interface. Any string that is a valid css color works.
    primaryColor?: string;

    // Whether the Simple Crypto interface will have rounded (CornerType.Rounded) or square (CornerType.Square) corners. The default is rounded.
    corners?: CornerType | string;

    // Whether the Simple Crypto interface will have a dark (ThemeMode.Dark) or a light (ThemeMode.Light) theme. The default is dark.
    mode?: ThemeMode | string;
};

CornerType

How the corners on the SDK will look.

enum CornerType {
    Rounded = "rounded",
    Square = "square",
}

ThemeMode

The different theme types available.

enum ThemeMode {
    Light = "light",
    Dark = "dark",
}

Example

import SimpleCryptoSDK, { ThemeMode, CornerType } from "@simplecrypto/wallet-sdk";

const wallet = new SimpleCryptoSDK({
    siteTitle: "NFT Marketplace",
    siteIcon: "https://nft-marketplace.com/icon.png",
    theme: {
        mode: ThemeMode.Light,
        corners: CornerType.Square,
        primaryColor: "black",
    }
});

Preload

preload()

Preload the SDK. This method injects Simple Crypto’s iframe into your application.

preload can be called early in an app's lifecycle as an optimization.

If preload isn't called, this.request, this.open, etc. will inject the widget just-in-time.

If your application uses Static Site Generation or Server Site Rendering, you'll want to make sure that you only call preload() client-side.

Arguments

none

Returns

Promise<void>. The promise resolves when Simple Crypto has been injected in your application.


Open

open()

Open the Simple Crypto Widget. If Simple Crypto is not already initialized, it will be initialized when you call open().

This method can be useful for allowing users to view their assets or buy crypto.

Arguments

none

Returns

Promise<void>. The promise resolves when the Simple Crypto widget is open.


Close

close()

Close the Simple Crypto Widget. In most cases you’ll never have to use this method because users can exit out of the Simple Crypto widget themselves.

Arguments

none

Returns

void


Remove

remove()

Remove the Simple Crypto iframe from the DOM. If the Simple Crypto iframe is not currently in the DOM, this method does nothing.

Arguments

none

Returns

Promise<void>. The promise resolves when Simple Crypto has been removed from the DOM.


Request

request({ method: string, params: unknown[] })

EIP1193 request method for remote procedure calls. This method will often be too low level to interact with directly and will more likely be used by the ethereum library you’re using. See our Ethers.js Integration for more.

Arguments

ParameterTypeDescription
request.methodstringThe request method
request.paramsunknown[]objectThe request params

Refer to here for a fairly comprehensive list of rpc methods and their respective params.

Returns

Promise<any>. The promise resolves with the result of the remote procedure call.


Send Batch Transaction

sendBatchTransaction(transactions: Array<SimpleCryptoTransaction>): Promise<string>

Send a batch transaction. A batch transaction submits multiple transactions at once through the user's smart contract wallet. This is useful for submitting an approval transaction at the same time as a the transaction they want to send so they don't have to submit multiple transactions.

Under the hood, this method calls request which supports the eth_sendTransaction method with multiple transactions at once.

Arguments

ParameterTypeDescription
transactionsArray<SimpleCryptoTransaction>The transactions to send in a batch. Refer the the SimpleCryptoTransaction type below
interface SimpleCryptoTransaction {
    to: string;       // The address to send the transaction to
    value?: string; // The amount of the blockchains native token to send in the transaction
    data?: string;  // The data of the transaction which will specify the smart contract interaction
}

Returns

Promise<any>. The promise resolves with the result of the remote procedure call.


On

on(event: string | symbol, listener: (...args: any[]) => void)

EIP1193 method to observe specific events. Below are the currently supported events.

EventDescription
connectUser as logged in
disconnectUser has logged out
simpleCrypto#initializedSimple Crypto has initialized

Simple Crypto does not yet have a reason to support other EIP1193 events as users don’t have the ability to change chains, switch accounts (without logging out), etc..

Arguments

ParameterTypeDescription
eventstringThe event to listen for (see list above)
listener(...args: any[]) => voidThe callback function on an event

Returns

SimpleCryptoSDK. The function returns the current instance of the SimpleCryptoSDK in accordance with the EIP1193 specification.


Remove Listener

removeListener(event: string | symbol, listener: (...args: any[]) => void)

EIP1193 method cease observing events. Removes an event listener that was set by on().

Arguments

ParameterTypeDescription
eventstringThe event to listen for (see #On for supported events)
listener(...args: any[]) => voidThe callback function on an event.

Returns

SimpleCryptoSDK. The function returns the current instance of the SimpleCryptoSDK in accordance with the EIP1193 specification.


Activate

activate()

Prompt the user to login or create a wallet. If the user is logged in this activate will just return the users address.

Arguments

none

Returns

Promise<string | undefined>. The promise resolves with the user’s address.


Get Account

getAccount()

Get the user's address.

Arguments

none

Returns

Promise<string>. The promise resolves with the user’s address.


Get EOA Address

getEoaAddress()

💡

In most cases you should use simpleCrypto.getAccount() to get the user's address.

Under the hood, every user has 2 addresses, the address of their smart contract wallet and the address that controls their smart contract wallet, known as their Externally Owned Account (EOA). Most of the time you'll want to use simpleCrypto.getAccount() to get the user's account but this method is useful in rare cases like getting the user’s EOA address so you can sign a message with the user’s EOA.

Arguments

none

Returns

Promise<string>. The promise resolves with the user’s eoa address.

Sign EIP1271 Message

signMessageEip1271(message: string): Promise<string | undefined>

Signs a message with the user's smart contract wallet according to EIP1271.

Arguments

ParameterTypeDescription
messagestringThe message to sign

Returns

Promise<string | undefined>. The promise resolves with either a signature, or undefined if we couldn't get the user's smart contract wallet address.

Sign Message With EOA

signMessageFromEoa(message: string): Promise<string | undefined>

Arguments

ParameterTypeDescription
messagestringThe message to sign

Returns

Promise<string | undefined>. The promise resolves with either a signature, or undefined if we couldn't get the user's address.

Last updated on February 4, 2023