Send a Transaction
Before diving into this tutorial, please ensure you already have an asset wallet with some ETH(SEPOLIA)_ETHEREUM_SEPOLIA
tokens. You can also refer to Create a Wallet to create your own wallets.
This tutorial consists of an example of a transfer task. Check out Transaction Task to learn more.
In this tutorial, you will learn how to:
- Create a transfer task
- Approve and sign
- Track transaction progress and status
Create a Transfer Task
Consider a transaction scenario in which ETH(SEPOLIA)_ETHEREUM_SEPOLIA
tokens are sent from an asset wallet whose accountKey
is account4b8d2c00520646c8862b68420aa1bc55
to an external unknown address 0x9437A77E6BE3a7Bf5F3cfE611BfCd1Fd30BF95f5
with a transfer amount of 0.1 ETH.
Request Parameters
This example uses a transaction fee tier, which is for setting the txFeeLevel
parameter. For more information about transaction fees, please refer to Estimate Transaction Fee.
- TypeScript
- Golang
- Java
interface CreateTransactionRequest {
customerRefId: string;
coinKey: string;
txFeeLevel?: string;
feeRateDto?: {
feeRate?: string;
gasLimit?: string;
maxPriorityFee?: string;
maxFee?: string
};
txAmount: string;
sourceAccountKey: string;
sourceAccountType: string;
destinationAccountKey?: string;
destinationAccountType: string;
destinationAddress: string;
}
const request: CreateTransactionRequest = {
sourceAccountKey: 'account4b8d2c00520646c8862b68420aa1bc55',
sourceAccountType: 'VAULT_ACCOUNT',
destinationAccountType: 'ONE_TIME_ADDRESS',
destinationAddress: '0x9437A77E6BE3a7Bf5F3cfE611BfCd1Fd30BF95f5',
coinKey: 'ETH(SEPOLIA)_ETHEREUM_SEPOLIA',
txAmount: '0.1',
txFeeLevel: 'MIDDLE',
customerRefId: uuid(),
};
type CreateTransactionRequest struct {
CustomerRefId string `json:"customerRefId"`
CoinKey string `json:"coinKey,omitempty"`
TxFeeLevel string `json:"txFeeLevel,omitempty"`
FeeRateDto struct {
FeeRate string `json:"feeRate,omitempty"`
GasLimit string `json:"gasLimit,omitempty"`
MaxPriorityFee string `json:"maxPriorityFee,omitempty"`
MaxFee string `json:"maxFee,omitempty"`
} `json:"feeRateDto,omitempty"`
TxAmount string `json:"txAmount,omitempty"`
SourceAccountKey string `json:"sourceAccountKey,omitempty"`
SourceAccountType string `json:"sourceAccountType,omitempty"`
DestinationAccountKey string `json:"destinationAccountKey,omitempty"`
DestinationAccountType string `json:"destinationAccountType,omitempty"`
DestinationAddress string `json:"destinationAddress,omitempty"`
}
createTransactionRequest := CreateTransactionRequest{
SourceAccountKey: "account4b8d2c00520646c8862b68420aa1bc55",
SourceAccountType: "VAULT_ACCOUNT",
DestinationAccountType: "ONE_TIME_ADDRESS",
DestinationAddress: "0x9437A77E6BE3a7Bf5F3cfE611BfCd1Fd30BF95f5",
CoinKey: "ETH(SEPOLIA)_ETHEREUM_SEPOLIA",
TxAmount: "0.1",
TxFeeLevel: "MIDDLE",
CustomerRefId: uuid.New().String(),
}
public class CreateTransactionRequest {
private String customerRefId;
private String coinKey;
private String txFeeLevel;
private String txAmount;
private String sourceAccountKey;
private String sourceAccountType;
private String destinationAccountKey;
private String destinationAccountType;
private String destinationAddress;
}
CreateTransactionRequest createTransactionRequest = new CreateTransactionRequest();
createTransactionRequest.setSourceAccountKey("account4b8d2c00520646c8862b68420aa1bc55");
createTransactionRequest.setSourceAccountType("VAULT_ACCOUNT");
createTransactionRequest.setDestinationAccountType("ONE_TIME_ADDRESS");
createTransactionRequest.setDestinationAddress("0x9437A77E6BE3a7Bf5F3cfE611BfCd1Fd30BF95f5");
createTransactionRequest.setCoinKey("ETH(SEPOLIA)_ETHEREUM_SEPOLIA");
createTransactionRequest.setTxAmount("0.1");
createTransactionRequest.setTxFeeLevel("MIDDLE");
createTransactionRequest.setCustomerRefId(UUID.randomUUID().toString());
Request the Interface
- TypeScript
- Golang
- Java
interface CreateTransactionResponse {
txKey: string;
}
const response = await client.doRequest<CreateTransactionRequest, CreateTransactionResponse>('/v2/transactions/create', request);
type CreateTransactionResponse struct {
TxKey string `json:"txKey"`
}
var createTransactionResponse CreateTransactionResponse
transactionApi.SendTransaction(createTransactionRequest, &createTransactionResponse)
public class CreateTransactionResponse {
private String txKey;
}
CreateTransactionResponse createTransactionResponse = ServiceExecutor.execute(transactionApi.createTransaction(createTransactionRequest));
Example Response Data
txKey
is a unique identifier for a transaction.
{
"txKey": "tx46461daa9b7a4612abce99e7ce598844"
}
Approve and Sign
Once a transaction task has been created, the system will proceed with either manual or automated approval via the API Co-Signer based on your policies.
- Manual Approval
- API Co-Signer Approval
Transaction Progress and Status
The created transaction task will undergo approval, signing, broadcasting, on-chain confirmation, etc. You can track the status of all transactions here. We also suggest using Webhook
to acquire time-sensitive status updates and signature results.
You can track transaction tasks with webhook by configuring the Webhook URL in Settings -> API on Safeheron Web Console.
For Your Reference
The code described in this tutorial is open-sourced on Safeheron's GitHub. For the full source code:
At this point, you have learned how to create a transfer task. You can learn more about creating other types of transactions through the API.