|
1 | 1 | ---
|
2 | 2 | title: Quick Start Guide
|
3 | 3 | ---
|
| 4 | + |
| 5 | +The Token-2022 program provides confidential transfer functionality through the |
| 6 | +confidential transfer extension. |
| 7 | + |
| 8 | +This guide explains how to use the confidential transfer extension. |
| 9 | + |
| 10 | +Please see the [Token-2022 Introduction](../token-2022) for more general information |
| 11 | +about Token-2022 and the concept of extensions. |
| 12 | + |
| 13 | +## Setup |
| 14 | + |
| 15 | +See the [Token Setup Guide](../token#setup) to install the client utilities. |
| 16 | +Token-2022 shares the same CLI and NPM packages for maximal compatibility. |
| 17 | + |
| 18 | +### Example: Create a mint with confidential transfers |
| 19 | + |
| 20 | +To create a new mint with confidential transfers enabled, run: |
| 21 | + |
| 22 | +```console |
| 23 | +$ spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token --enable-confidential-transfers auto |
| 24 | +``` |
| 25 | + |
| 26 | +The `auto` keyword means that any token user can permissionlessly configure their |
| 27 | +account to perform confidential transfers. |
| 28 | + |
| 29 | +If you would like to gate confidential transfer functionality to certain users, |
| 30 | +you can set the approve policy to `manual`. With this approve policy, all users |
| 31 | +must be manually approved to perform confidential transfers. Anyone can still use |
| 32 | +the token non-confidentially. |
| 33 | + |
| 34 | +Note that you must configure your mint with confidential transfers at creation, |
| 35 | +and cannot add it later. |
| 36 | + |
| 37 | +### Example: Configure a token account for confidential transfers |
| 38 | + |
| 39 | +Account creation works as normal: |
| 40 | + |
| 41 | +```console |
| 42 | +$ spl-token create-account <MINT_PUBKEY> |
| 43 | +``` |
| 44 | + |
| 45 | +Once the user creates their account, they may configure it for confidential transfers: |
| 46 | + |
| 47 | +```console |
| 48 | +$ spl-token configure-confidential-transfer-account --address <ACCOUNT_PUBKEY> |
| 49 | +``` |
| 50 | + |
| 51 | +Note that only the account owner may configure confidential transfers for their |
| 52 | +account: only they should set the encryption key for their account. This is |
| 53 | +different from normal accounts, such as associated-token-accounts, where someone |
| 54 | +can create another person's account. |
| 55 | + |
| 56 | +### Example: Deposit confidential tokens |
| 57 | + |
| 58 | +Once the user configures their account for confidential transfers and has a |
| 59 | +non-confidential token balance, they must deposit their tokens from non-confidential |
| 60 | +to confidential: |
| 61 | + |
| 62 | +```console |
| 63 | +$ spl-token deposit-confidential-tokens <MINT_PUBKEY> <AMOUNT> --address <ACCOUNT_PUBKEY> |
| 64 | +``` |
| 65 | + |
| 66 | +Note that the deposited tokens will no longer exist on the account's non-confidential |
| 67 | +balance: they have been completely moved into the confidential balance. |
| 68 | + |
| 69 | +### Example: Apply pending balance |
| 70 | + |
| 71 | +Whenever an account receives confidential tokens from transfers or deposits, the |
| 72 | +balance will appear in the "pending" balance, which means that the user cannot |
| 73 | +immediately access the funds. |
| 74 | + |
| 75 | +To move a balance from "pending" to "available", simply run: |
| 76 | + |
| 77 | +```console |
| 78 | +$ spl-token apply-pending-balance --address <ACCOUNT_PUBKEY> |
| 79 | +``` |
| 80 | + |
| 81 | +### Example: Transfer confidential tokens |
| 82 | + |
| 83 | +Once an account has an available balance, a user may finally transfer the tokens |
| 84 | +to another account that has been configured for confidential transfers! |
| 85 | + |
| 86 | +```console |
| 87 | +$ spl-token transfer <MINT_PUBKEY> <AMOUNT> <DESTINATION_PUBKEY> --confidential |
| 88 | +``` |
| 89 | + |
| 90 | +This operation takes a little bit longer since it requires multiple dependent |
| 91 | +transactions, but it's still only a few seconds. |
| 92 | + |
| 93 | +### Example: Withdraw confidential tokens |
| 94 | + |
| 95 | +A user whose account has an available confidential balance may withdraw those |
| 96 | +tokens back into their non-confidential balance. |
| 97 | + |
| 98 | +```console |
| 99 | +$ spl-token withdraw-confidential-tokens <MINT_PUBKEY> <AMOUNT> --address <ACCOUNT_PUBKEY> |
| 100 | +``` |
| 101 | + |
| 102 | +Be sure to apply any pending balance before running this command to be sure that |
| 103 | +all tokens are available. |
0 commit comments