|
| 1 | +--- |
| 2 | +title: Approve and Revoke Delegates |
| 3 | +sidebarTitle: Approve / Revoke |
| 4 | +description: Rust client guide to approve and revoke delegates for Light Token accounts. Includes step-by-step implementation and full code examples. |
| 5 | +keywords: ["approve delegate solana", "revoke delegate solana", "token delegation"] |
| 6 | +--- |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; |
| 11 | +import FullSetup from "/snippets/setup/full-setup.mdx"; |
| 12 | +import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; |
| 13 | +import { |
| 14 | + splApproveCode, |
| 15 | + lightApproveCode, |
| 16 | + splRevokeCode, |
| 17 | + lightRevokeCode, |
| 18 | + splApproveRustCode, |
| 19 | + lightApproveRustCode, |
| 20 | + splRevokeRustCode, |
| 21 | + lightRevokeRustCode, |
| 22 | +} from "/snippets/code-samples/code-compare-snippets.jsx"; |
| 23 | +import TsApproveActionCode from "/snippets/code-snippets/light-token/approve-revoke/approve-action.mdx"; |
| 24 | +import TsRevokeActionCode from "/snippets/code-snippets/light-token/approve-revoke/revoke-action.mdx"; |
| 25 | +import ApproveActionCode from "/snippets/code-snippets/light-token/approve-revoke/rust-client/approve-action.mdx"; |
| 26 | +import ApproveInstructionCode from "/snippets/code-snippets/light-token/approve-revoke/rust-client/approve-instruction.mdx"; |
| 27 | +import RevokeActionCode from "/snippets/code-snippets/light-token/approve-revoke/rust-client/revoke-action.mdx"; |
| 28 | +import RevokeInstructionCode from "/snippets/code-snippets/light-token/approve-revoke/rust-client/revoke-instruction.mdx"; |
| 29 | +import ApproveAnchorProgramCode from "/snippets/code-snippets/light-token/approve/anchor-program/full-example.mdx"; |
| 30 | +import RevokeAnchorProgramCode from "/snippets/code-snippets/light-token/revoke/anchor-program/full-example.mdx"; |
| 31 | + |
| 32 | +1. Approve grants a delegate permission to transfer up to a specified amount of tokens from your account. |
| 33 | + * Each token account can have only one delegate at a time. |
| 34 | + * Any new approval overwrites the previous one. |
| 35 | +2. Revoke removes all delegate permissions from a Light Token account. |
| 36 | +3. Only the token account owner can approve or revoke delegates. |
| 37 | + |
| 38 | +<Tabs> |
| 39 | + |
| 40 | +<Tab title="TypeScript Client"> |
| 41 | + |
| 42 | +<Tabs> |
| 43 | +<Tab title="Approve"> |
| 44 | + |
| 45 | +`approve` grants a delegate permission to transfer up to a specified amount of tokens. |
| 46 | + |
| 47 | +<CodeCompare |
| 48 | + firstCode={lightApproveCode} |
| 49 | + secondCode={splApproveCode} |
| 50 | + firstLabel="light-token" |
| 51 | + secondLabel="SPL" |
| 52 | +/> |
| 53 | + |
| 54 | +</Tab> |
| 55 | +<Tab title="Revoke"> |
| 56 | + |
| 57 | +`revoke` removes all delegate permissions from a Light Token account. |
| 58 | + |
| 59 | +<CodeCompare |
| 60 | + firstCode={lightRevokeCode} |
| 61 | + secondCode={splRevokeCode} |
| 62 | + firstLabel="light-token" |
| 63 | + secondLabel="SPL" |
| 64 | +/> |
| 65 | + |
| 66 | +</Tab> |
| 67 | +</Tabs> |
| 68 | + |
| 69 | +<Info> |
| 70 | + Find the source code |
| 71 | + [here](https://github.com/Lightprotocol/examples-light-token/tree/main/typescript-client/actions). |
| 72 | +</Info> |
| 73 | + |
| 74 | +<Steps> |
| 75 | +<Step> |
| 76 | +### Approve a delegate |
| 77 | + |
| 78 | +<FullSetup /> |
| 79 | + |
| 80 | +<TsApproveActionCode /> |
| 81 | + |
| 82 | +</Step> |
| 83 | + |
| 84 | +<Step> |
| 85 | +### Revoke a delegate |
| 86 | + |
| 87 | +<TsRevokeActionCode /> |
| 88 | + |
| 89 | +</Step> |
| 90 | +</Steps> |
| 91 | + |
| 92 | +</Tab> |
| 93 | + |
| 94 | +<Tab title="Rust Client"> |
| 95 | + |
| 96 | +<Tabs> |
| 97 | +<Tab title="Approve"> |
| 98 | + |
| 99 | +<CodeCompare |
| 100 | + firstCode={lightApproveRustCode} |
| 101 | + secondCode={splApproveRustCode} |
| 102 | + firstLabel="light-token" |
| 103 | + secondLabel="SPL" |
| 104 | + language="rust" |
| 105 | +/> |
| 106 | + |
| 107 | +</Tab> |
| 108 | +<Tab title="Revoke"> |
| 109 | + |
| 110 | +<CodeCompare |
| 111 | + firstCode={lightRevokeRustCode} |
| 112 | + secondCode={splRevokeRustCode} |
| 113 | + firstLabel="light-token" |
| 114 | + secondLabel="SPL" |
| 115 | + language="rust" |
| 116 | +/> |
| 117 | + |
| 118 | +</Tab> |
| 119 | +</Tabs> |
| 120 | + |
| 121 | +<Steps> |
| 122 | +<Step> |
| 123 | +### Prerequisites |
| 124 | + |
| 125 | +<TokenClientPrerequisites /> |
| 126 | + |
| 127 | +</Step> |
| 128 | + |
| 129 | +<Step> |
| 130 | +### Approve or revoke delegates |
| 131 | + |
| 132 | +<Info> |
| 133 | + Find the full example including shared test utilities in the |
| 134 | + [examples-light-token](https://github.com/Lightprotocol/examples-light-token/tree/main/rust-client). |
| 135 | +</Info> |
| 136 | + |
| 137 | +<Tabs> |
| 138 | +<Tab title="Approve"> |
| 139 | +<Tabs> |
| 140 | +<Tab title="Action"> |
| 141 | +<ApproveActionCode /> |
| 142 | +</Tab> |
| 143 | +<Tab title="Instruction"> |
| 144 | +<ApproveInstructionCode /> |
| 145 | +</Tab> |
| 146 | +</Tabs> |
| 147 | +</Tab> |
| 148 | +<Tab title="Revoke"> |
| 149 | +<Tabs> |
| 150 | +<Tab title="Action"> |
| 151 | +<RevokeActionCode /> |
| 152 | +</Tab> |
| 153 | +<Tab title="Instruction"> |
| 154 | +<RevokeInstructionCode /> |
| 155 | +</Tab> |
| 156 | +</Tabs> |
| 157 | +</Tab> |
| 158 | +</Tabs> |
| 159 | + |
| 160 | +</Step> |
| 161 | +</Steps> |
| 162 | +</Tab> |
| 163 | + |
| 164 | +</Tabs> |
| 165 | + |
| 166 | +# Next Steps |
| 167 | + |
| 168 | +<Card |
| 169 | + title="Go back to the overview for the Light Token standard" |
| 170 | + icon="chevron-right" |
| 171 | + color="#0066ff" |
| 172 | + href="/light-token/welcome" |
| 173 | + horizontal |
| 174 | +/> |
0 commit comments