Example project demonstrating Fystack Wallet SDK usage for wallet management, deposits, withdrawals, and blockchain transfers.
- Node.js 18+
- Fystack API credentials (API Key and Secret)
- A Fystack workspace
npm install- Copy the example environment file:
cp .env.example .env- Update
.envwith your credentials:
FYSTACK_API_KEY=your_api_key_here
FYSTACK_API_SECRET=your_api_secret_here
FYSTACK_WORKSPACE_ID=your_workspace_id_here
FYSTACK_ENVIRONMENT=sandbox| Command | Description |
|---|---|
npm run create-wallet |
Create a new MPC wallet |
npm run get-deposit-address |
Get deposit addresses for a wallet |
npm run create-withdrawal |
Request a withdrawal from a wallet |
npm run eth-transfer |
Execute an Ethereum transfer |
npm run solana-transfer |
Execute a Solana transfer |
npm run get-public-key |
Get the public key for a wallet |
Create a new wallet in your Fystack workspace.
npm run create-wallet=== Create Wallet Example ===
[FystackSDK] Polling wallet creation status...
[FystackSDK] Polling wallet creation status...
[FystackSDK] Polling wallet creation status...
[FystackSDK] Polling wallet creation status...
[FystackSDK] Polling wallet creation status...
[FystackSDK] Wallet creation completed with status: success
Wallet created successfully!
Wallet ID: f4d44a3e-233b-4aff-8b91-8144b1f5820d
Status: success
The example creates an MPC wallet by default. You can change the wallet type in src/examples/create-wallet.ts:
// MPC Wallet (default) - Multi-Party Computation
walletType: WalletType.MPC
// Hyper Wallet - Alternative wallet type
walletType: WalletType.Hyper| Wallet Type | Description |
|---|---|
WalletType.MPC |
Multi-Party Computation wallet with distributed key management |
WalletType.Hyper |
Hyper wallet for different use cases |
- Save the
Wallet IDfrom the response - you'll need it for other operations like deposits and withdrawals - Add the wallet ID to your
.envfile:WALLET_ID=your_wallet_id_here
Request a withdrawal from your Fystack wallet to an external address.
-
Set
WALLET_IDin your.envfileYou need an existing wallet ID. You can get this by running
npm run create-walletfirst, or from your Fystack dashboard.WALLET_ID=your_wallet_id_here
-
Get the
ASSET_IDfrom the APIThe asset ID identifies which cryptocurrency you want to withdraw. Fetch it from the Fystack API:
curl "https://api.fystack.io/api/v1/assets?symbol=ETH"This returns the asset details including the
id. Add it to your.env:ASSET_ID=your_asset_id_here
-
Set the recipient address
ETH_RECIPIENT_ADDRESS=0xYourRecipientAddressHere
npm run create-withdrawal=== Create Withdrawal Example ===
Requesting withdrawal...
Wallet ID: e0341fe8-ddd4-4d40-ad05-31516f8e8ca0
Asset ID: a469642e-5466-4d69-834d-537f33ee5c81
Recipient: 0x0000000000000000000000000000000000000000
Amount: 0.0001
[FystackSDK] Requesting withdrawal from wallet e0341fe8-ddd4-4d40-ad05-31516f8e8ca0
[FystackSDK] Withdrawal request completed, auto_approved: false
Withdrawal request submitted!
Auto Approved: false
Withdrawal ID: 9ed13061-9f9c-4bd3-a61a-bc85e97f0d9e
Status: PENDING_APPROVAL
| Field | Description |
|---|---|
Auto Approved |
Whether the withdrawal was automatically approved based on your workspace policies |
Withdrawal ID |
Unique identifier for tracking the withdrawal |
Status |
Current status (PENDING_APPROVAL, APPROVED, PROCESSING, COMPLETED, FAILED) |
- Withdrawals may require manual approval depending on your workspace configuration
- The default amount is
0.0001- modify the code to change this - Ensure your wallet has sufficient balance for the withdrawal amount plus network fees
| Variable | Required | Description |
|---|---|---|
FYSTACK_API_KEY |
Yes | Your Fystack API key |
FYSTACK_API_SECRET |
Yes | Your Fystack API secret |
FYSTACK_WORKSPACE_ID |
Yes | Your workspace ID |
FYSTACK_ENVIRONMENT |
No | sandbox (default), production, or local |
WALLET_ID |
For some ops | Wallet ID for operations requiring an existing wallet |
ASSET_ID |
For withdrawals | Asset ID (get from /api/v1/assets?symbol=ETH) |
ETH_RECIPIENT_ADDRESS |
For ETH ops | Ethereum recipient address |
SOLANA_RECIPIENT_ADDRESS |
For SOL ops | Solana recipient address |
ETHEREUM_RPC_URL |
No | Custom Ethereum RPC (default: Sepolia testnet) |
SOLANA_RPC_URL |
No | Custom Solana RPC (default: Devnet) |
The FYSTACK_ENVIRONMENT variable maps to SDK environment constants:
.env Value |
SDK Constant | Description |
|---|---|---|
sandbox |
Environment.Sandbox |
Sandbox/testing environment (default) |
production |
Environment.Production |
Production environment |
local |
Environment.Local |
Local development environment |