Create a Wallet
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:
- Create a wallet
- 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
- TypeScript
- Golang
- Java
interface CreateAccountRequest {
accountName?: string;
}
const request: CreateAccountRequest = {
accountName: 'first-wallet-account',
};
type CreateAccountRequest struct {
AccountName string `json:"accountName,omitempty"`
}
createAccountRequest := CreateAccountRequest{
AccountName: "first-wallet-account",
}
public class CreateAccountRequest {
private String accountName;
}
CreateAccountRequest createAccountRequest = new CreateAccountRequest();
createAccountRequest.setAccountName("first-wallet-account");
Request the Interface
- TypeScript
- Golang
- Java
interface CreateAccountResponse {
accountKey: string;
pubKeys: Array<{
signAlg: string;
pubKey: string;
}>;
}
const response = await client.doRequest<CreateAccountRequest, CreateAccountResponse>('/v1/account/create', request);
type CreateAccountResponse struct {
AccountKey string `json:"accountKey"`
PubKeys []struct {
SignAlg string `json:"signAlg"`
PubKey string `json:"pubKey"`
} `json:"pubKeys"`
}
var createAccountResponse CreateAccountResponse
accountApi.CreateAccount(createAccountRequest, &createAccountResponse)
public class CreateAccountResponse {
private String accountKey;
private List<PubKey> pubKeys;
static class PubKey{
private String signAlg;
private String pubKey;
}
}
CreateAccountResponse createAccountResponse = ServiceExecutor.execute(accountApi.createAccount(createAccountRequest));
Example Response Data
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
- TypeScript
- Golang
- Java
interface AddCoinRequest {
coinKey: string;
accountKey: string;
}
const request: AddCoinRequest = {
coinKey: 'ETH(SEPOLIA)_ETHEREUM_SEPOLIA',
accountKey: 'account4b8d2c00520646c8862b68420aa1bc55',
};
type AddCoinRequest struct {
CoinKey string `json:"coinKey,omitempty"`
AccountKey string `json:"accountKey,omitempty"`
}
addCoinRequest := AddCoinRequest{
AccountKey: "account4b8d2c00520646c8862b68420aa1bc55",
CoinKey: "ETH(SEPOLIA)_ETHEREUM_SEPOLIA",
}
public class AddCoinRequest {
private String coinKey;
private String accountKey;
}
AddCoinRequest addCoinRequest = new AddCoinRequest();
addCoinRequest.setAccountKey("account4b8d2c00520646c8862b68420aa1bc55");
addCoinRequest.setCoinKey("ETH(SEPOLIA)_ETHEREUM_SEPOLIA");
Request the Interface
- TypeScript
- Golang
- Java
interface AddCoinResponse {
[index: number]: {
address: string;
addressType: string;
amlLock: string;
}
}
const response = await client.doRequest<AddCoinRequest, AddCoinResponse>('/v1/account/coin/create', request);
type AddCoinResponse []struct {
Address string `json:"address,omitempty"`
AddressType string `json:"addressType,omitempty"`
AmlLock string `json:"amlLock,omitempty"`
}
var addCoinResponse AddCoinResponse
accountApi.AddCoin(addCoinRequest, &addCoinResponse)
public class AddCoinResponse {
private String address;
private String addressType;
private String amlLock;
}
List<AddCoinResponse> addCoinResponseList = ServiceExecutor.execute(accountApi.addCoin(addCoinRequest));
Example Response Data
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.
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.
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: