4.1 KiB
Send and Receive Tokens
Receive Tokens
To receive tokens, you will need an address for others to send tokens to. In Solana, an address is the public key of a keypair. There are a variety of techniques for generating keypairs. The method you choose will depend on how you choose to store keypairs. Keypairs are stored in wallets. Before receiving tokens, you will need to choose a wallet and generate keys. Once completed, you should have a public key for each keypair you generated. The public key is a long string of base58 characters. Its length varies from 32 to 44 characters.
Using Solana CLI
Before running any Solana CLI commands, let's go over some conventions that you will see across all commands. First, the Solana CLI is actually a collection of different commands for each action you might want to take. You can view the list of all possible commands by running:
solana --help
To zoom in on how to use a particular command, run:
solana <COMMAND> --help
where you replace the text <COMMAND>
with the name of the command you want
to learn more about.
The command's usage message will typically contain words such as <AMOUNT>
,
<ACCOUNT_ADDRESS>
or <KEYPAIR>
. Each word is a placeholder for the type of
text you can execute the command with. For example, you can replace <AMOUNT>
with a number such as 42
or 100.42
. You can replace <ACCOUNT_ADDRESS>
with
the base58 encoding of your public key. For <KEYPAIR>
, it depends on what type
of wallet you chose. If you chose an fs wallet, that path might be
~/my-solana-wallet/my-keypair.json
. If you chose a paper wallet, use the
keyword ASK
, and the Solana CLI will prompt you for your seed phrase. If
you chose a hardware wallet, use your keypair URL, such as usb://ledger?key=0
.
Test-drive your Public Keys
Before sharing your public key with others, you may want to first ensure the key is valid and that you indeed hold the corresponding private key.
Try and airdrop yourself some play tokens on the developer testnet, called Devnet:
solana airdrop 10 <RECIPIENT_ACCOUNT_ADDRESS> --url http://devnet.solana.com
where you replace the text <RECIPIENT_ACCOUNT_ADDRESS>
with your base58-encoded
public key.
Confirm the airdrop was successful by checking the account's balance.
It should output 10 SOL
:
solana balance <ACCOUNT_ADDRESS> --url http://devnet.solana.com
Next, prove that you own those tokens by transferring them. The Solana cluster will only accept the transfer if you sign the transaction with the private key corresponding to the sender's public key in the transaction.
First, we will need a public key to receive our tokens. Create a second keypair and record its pubkey:
solana-keygen new --no-passphrase --no-outfile
The output will contain the public key after the text pubkey:
. Copy the
public key. We will use it in the next step.
============================================================================
pubkey: GKvqsuNcnwWqPzzuhLmGi4rzzh55FhJtGizkhHaEJqiV
============================================================================
solana transfer --from <KEYPAIR> <RECIPIENT_ACCOUNT_ADDRESS> 5--url http://devnet.solana.com --fee-payer <KEYPAIR>
where you replace <KEYPAIR>
with the path to a keypair in your wallet,
and replace <RECIPIENT_ACCOUNT_ADDRESS>
with the output of solana-keygen new
above.
Confirm the updated balances with solana balance
:
solana balance <ACCOUNT_ADDRESS> --url http://devnet.solana.com
where <ACCOUNT_ADDRESS>
is either the public key from your keypair or the
recipient's public key.
Send Tokens
If you already hold SOL and want to send tokens to someone, you will need
a path to your keypair, their base58-encoded public key, and a number of
tokens to transfer. Once you have that collected, you can transfer tokens
with the solana transfer
command:
solana transfer --from <KEYPAIR> <RECIPIENT_ACCOUNT_ADDRESS> <AMOUNT> --fee-payer <KEYPAIR>
Confirm the updated balances with solana balance
:
solana balance <ACCOUNT_ADDRESS>