Skip to main content

Create a Wallet

tip

Before reading this tutorial, it is assumed that you already have an API Key with Manage Wallet Account permission. If you have not yet created an API Key, you can do so by viewing the Create an API Key tutorial.

Safeheron offers two types of wallets: Asset Wallet and Web3 Wallet. Click here to learn more.

With this tutorial, you will use the API to:

  1. Create a wallet
  2. Add a token to the asset wallet

And lastly, transfer some tokens to the wallet via the Sepolia Faucet.

Create an Asset Wallet

Request Parameters

interface CreateAccountRequest {
accountName?: string;
}

const request: CreateAccountRequest = {
accountName: 'first-wallet-account',
};

Request the Interface

interface CreateAccountResponse {
accountKey: string;
pubKeys: Array<{
signAlg: string;
pubKey: string;
}>;
}

const response = await client.doRequest<CreateAccountRequest, CreateAccountResponse>('/v1/account/create', request);

Example Response Data

tip

The accountKey data, which is unique to a wallet, is saved for future use.

{
"accountKey": "account4b8d2c00520646c8862b68420aa1bc55",
"pubKeys": [
{
"signAlg": "secp256k1",
"pubKey": "03ba5cef******490469dadd2a"
}
]
}

Add Tokens to the Asset Wallet

SepoliaETH is the native token of the Sepolia test network, the coinKey corresponding to this token in Safeheron's platform is ETH(SEPOLIA)_ETHEREUM_SEPOLIA, let's add the ETH(SEPOLIA)_ETHEREUM_SEPOLIA token as an example to illustrate how to add a token to the asset wallet. Click here to see a list of all tokens supported by Safeheron.

Request Parameters

interface AddCoinRequest {
coinKey: string;
accountKey: string;
}

const request: AddCoinRequest = {
coinKey: 'ETH(SEPOLIA)_ETHEREUM_SEPOLIA',
accountKey: 'account4b8d2c00520646c8862b68420aa1bc55',
};

Request the Interface

interface AddCoinResponse {
[index: number]: {
address: string;
addressType: string;
amlLock: string;
}
}

const response = await client.doRequest<AddCoinRequest, AddCoinResponse>('/v1/account/coin/create', request);

Example Response Data

tip

The address shown in the data below is the address of the ETH(SEPOLIA)_ETHEREUM_SEPOLIA token.

[
{
"address": "0x1ec4fb20d8955d9d6a4ae45f01af04e170c0c022",
"addressType": "DEFAULT",
"amlLock": "NO"
}
]

Transferring Tokens from Sepolia Faucet

After obtaining the token address whose coinKey is ETH(SEPOLIA)_ETHEREUM_SEPOLIA, you can now transfer ETH from the Sepolia Faucet to your asset wallet.As shown below, we enter the wallet address corresponding to the ETH(SEPOLIA)_ETHEREUM_SEPOLIA token. Click Send Me ETH, and the Sepolia Faucet will transfer the requested ETH to our wallet.

img

Webhook

From the time an asset is transferred to the time it is confirmed, a series of processes must be carried out. We suggest using Webhook to understand this procedure.

tip

To get the transaction process, the Webhook URL needs to be configured in the "Settings" on the Safeheron Web Console.

For Your Reference

The code described in this tutorial is open-sourced on Safeheron's GitHub. For the full source code:

After creating your own wallet and transferring funds to it, you can proceed to the next step: