2020-03-18 19:15:34 -07:00
|
|
|
# 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
|
2020-03-27 10:28:23 -07:00
|
|
|
tokens, you will need to [choose a wallet](../wallet/cli-wallets.md) and
|
2020-03-18 19:15:34 -07:00
|
|
|
[generate keys](generate-keys.md). 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:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
solana --help
|
|
|
|
```
|
|
|
|
|
|
|
|
To zoom in on how to use a particular command, run:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
solana <COMMAND> --help
|
|
|
|
```
|
|
|
|
|
|
|
|
where you replace the text `<COMMAND>` with the name of the command you want
|
|
|
|
to learn more about.
|
|
|
|
|
2020-03-20 09:36:55 -07:00
|
|
|
The command's usage message will typically contain words such as `<AMOUNT>`,
|
2020-03-22 22:44:55 -07:00
|
|
|
`<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
|
2020-03-18 19:15:34 -07:00
|
|
|
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
|
2020-03-22 22:44:55 -07:00
|
|
|
you chose a hardware wallet, use your keypair URL, such as `usb://ledger?key=0`.
|
2020-03-18 19:15:34 -07:00
|
|
|
|
|
|
|
### 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:
|
|
|
|
|
|
|
|
```bash
|
2020-03-22 22:44:55 -07:00
|
|
|
solana airdrop 10 <RECIPIENT_ACCOUNT_ADDRESS> --url http://devnet.solana.com
|
2020-03-18 19:15:34 -07:00
|
|
|
```
|
|
|
|
|
2020-03-22 22:44:55 -07:00
|
|
|
where you replace the text `<RECIPIENT_ACCOUNT_ADDRESS>` with your base58-encoded
|
|
|
|
public key.
|
2020-03-18 19:15:34 -07:00
|
|
|
|
|
|
|
Confirm the airdrop was successful by checking the account's balance.
|
|
|
|
It should output `10 SOL`:
|
|
|
|
|
|
|
|
```bash
|
2020-03-22 22:44:55 -07:00
|
|
|
solana balance <ACCOUNT_ADDRESS> --url http://devnet.solana.com
|
2020-03-18 19:15:34 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2020-03-22 22:44:55 -07:00
|
|
|
First, we will need a public key to receive our tokens. Create a second
|
2020-03-18 19:15:34 -07:00
|
|
|
keypair and record its pubkey:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
solana-keygen new --no-passphrase --no-outfile
|
|
|
|
```
|
|
|
|
|
|
|
|
The output will contain the public key after the text `pubkey:`. Copy the
|
2020-03-22 22:44:55 -07:00
|
|
|
public key. We will use it in the next step.
|
2020-03-18 19:15:34 -07:00
|
|
|
|
|
|
|
```text
|
|
|
|
============================================================================
|
|
|
|
pubkey: GKvqsuNcnwWqPzzuhLmGi4rzzh55FhJtGizkhHaEJqiV
|
|
|
|
============================================================================
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
2020-04-01 15:11:47 -07:00
|
|
|
solana transfer --from <KEYPAIR> <RECIPIENT_ACCOUNT_ADDRESS> 5--url http://devnet.solana.com --fee-payer <KEYPAIR>
|
2020-03-18 19:15:34 -07:00
|
|
|
```
|
|
|
|
|
2020-04-01 15:11:47 -07:00
|
|
|
where you replace `<KEYPAIR>` with the path to a keypair in your wallet,
|
2020-03-22 22:44:55 -07:00
|
|
|
and replace `<RECIPIENT_ACCOUNT_ADDRESS>` with the output of `solana-keygen new` above.
|
2020-03-18 19:15:34 -07:00
|
|
|
|
|
|
|
Confirm the updated balances with `solana balance`:
|
|
|
|
|
|
|
|
```bash
|
2020-03-22 22:44:55 -07:00
|
|
|
solana balance <ACCOUNT_ADDRESS> --url http://devnet.solana.com
|
2020-03-18 19:15:34 -07:00
|
|
|
```
|
|
|
|
|
2020-03-22 22:44:55 -07:00
|
|
|
where `<ACCOUNT_ADDRESS>` is either the public key from your keypair or the
|
2020-03-18 19:15:34 -07:00
|
|
|
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:
|
|
|
|
|
|
|
|
```bash
|
2020-04-01 15:11:47 -07:00
|
|
|
solana transfer --from <KEYPAIR> <RECIPIENT_ACCOUNT_ADDRESS> <AMOUNT> --fee-payer <KEYPAIR>
|
2020-03-18 19:15:34 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
Confirm the updated balances with `solana balance`:
|
|
|
|
|
|
|
|
```bash
|
2020-03-22 22:44:55 -07:00
|
|
|
solana balance <ACCOUNT_ADDRESS>
|
2020-03-18 19:15:34 -07:00
|
|
|
```
|