Overview
A transfer refers to sending tokens from one account to another on a blockchain network. Token transfers are supported on EVM Accounts, EVM Smart Accounts and Solana Accounts. EVM Accounts can transfer native ETH or ERC-20 tokens, and Solana Accounts can transfer native SOL or SPL tokens.Prerequisites
- Python 3.10+ or Node.js 20+
- CDP API credentials (See the Quickstart guide for more information)
- Required packages:
@solana/web3.js
instead of viem
on TypeScript, and solana
instead of web3
on Python:
If you complete the Quickstart, you will have a complete working setup to complete this tutorial.
EVM Account transfer
This section will walk you through transferring funds from an externally owned account (EOA).1. Create accounts
First, create two EOAs:2. Transfer ETH to account
Next, transfer ETH using the accounts you created earlier.3. Wait for transfer result
Finally, wait for the transfer to be confirmed.Smart Account transfer
This section will walk you through transferring funds from a Smart Account to an EOA.1. Create Smart Account
First, we create an owner account to assign to our newly created Smart Account:2. Create receiver account
Create a receiver account:3. Transfer ETH to account
Perform the transfer using the smart account:4. Wait for transfer result
Finally, wait for the transfer to be confirmed.Solana Account transfer
This section will walk you through transferring funds from a Solana Account.1. Create accounts
First, create two Solana Accounts:2. Transfer SOL to account
Perform the transfer using the Solana Account:3. Wait for transfer result
Finally, wait for the transfer to be confirmed.Complete example
A complete, runnable example can be found below. In the code below, we:- Create two EVM EOAs
- Transfer ETH from one EOA to another
- Wait for the transfer to be confirmed
- Create a Smart Account
- Transfer ETH from the Smart Account to an EOA
- Wait for the transfer to be confirmed
- Create two Solana Accounts
- Transfer SOL from one Solana Account to another
- Wait for the transfer to be confirmed
Transferring ERC-20 Tokens or SPL Tokens
In the examples above, we transferred native tokens (eth
and sol
). Using the transfer
method, you can also easily transfer ERC-20 tokens or SPL tokens, like USDC.
The transfer
method itself can receive usdc
as the value for the token
parameter:
amount
parameter is specified as 10000
for USDC. This is because USDC has 6 decimal places, so 10000
is equivalent to 0.01 USDC
.
To work with more human-readable values, you can use the parseUnits
function from viem
if using TypeScript, or CDP’s parse_units
function if using Python:
transfer
method can also receive an arbitrary token contract address as the value for the token
parameter:
Video: Watch and learn
Watch this video for a walkthrough of the transfer process:What to read next
- Managing Accounts: Learn tips and best practices for managing your accounts
- Accounts: More information on the different types of accounts available using the v2 Server Wallet