
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@civic/token-guard
Advanced tools
A composable gateway program for Solana dApps written in Anchor and using Civic Pass.
With TokenGuard, dApp developers can protect access to any dApp that accepts tokens as payment, such as a Metaplex CandyMachine mint, without requiring any on-chain smart-contract changes.
NOTE: TokenGuard is currently in beta on devnet only and is unaudited.
$ yarn global add @civic/token-guard
$ token-guard create --help
Let's say you want to set up a CandyMachine that mints NFTs at x Sol each, and you want to restrict purchase only to holders of a valid Civic Pass.
Set up a TokenGuard that exchanges Sol for a new token T, created by TokenGuard (the mint authority is a PDA owned by TokenGuard), if the user has a valid Civic Pass.
Set up a CandyMachine that accepts token T instead of Sol
In your UI, add a TokenGuard exchange instruction to the mint transaction.
Note: the equivalent pattern applies to other protocols.

TokenGuard has an "allowance" feature, that allows only x purchases per wallet, per token-guard.
For example, if the allowance is set to 1, a user with a valid Civic Pass associated with their wallet can make one purchase only.
They cannot use a second wallet, unless that wallet also has a Civic Pass associated with it. Civic Passes are non-transferable.
Set up an allowance with the --allowance flag.
[ ] Support for SPL Token (accept SPL instead of Sol)
[ ] Support for membership tokens (non-consumed tokens)
[ ] Mainnet deployment
[ ] Audit
Example: CandyMachine using the dummy Civic Pass: "tgnuXXNMDLK8dy7Xm1TdeGyc95MDym4bvAQCwcW21Bf"
Get the real civic pass address from https://docs.civic.com
$ yarn global add @civic/token-guard
$ token-guard create
TokenGuard created
ID: FeHQD2mEHScoznRZQHFGTtTZALfPpDLCx8Pg4HyDYVwy
Mint: 6zV7KfgzuNHTEm922juUSFwGJ472Kx6w8J7Gf6kAYuzh
(TODO include this in the TG initialisation step?)
spl-token -u devnet create-account 6zV7KfgzuNHTEm922juUSFwGJ472Kx6w8J7Gf6kAYuzh
Check out the metaplex repository and follow the steps to install the metaplex CLI.
See Candy Machine Overview for details
# Find the token account created in step 2
MINT=6zV7KfgzuNHTEm922juUSFwGJ472Kx6w8J7Gf6kAYuzh
TOKEN_ACCOUNT=$(spl-token -u devnet address --token ${MINT} -v --output json | jq '.associatedTokenAddress' | tr -d '"')
# Upload the assets
metaplex upload assets -k ${HOME}/.config/solana/id.json -c devnet
# Create the candy machine instance, referencing the token account
metaplex create_candy_machine -k ${HOME}/.config/solana/id.json -c devnet -t ${MINT} -p 1 -a ${TOKEN_ACCOUNT}
# Set the start date
metaplex update_candy_machine -d now -k ${HOME}/.config/solana/id.json -c devnet
You need to make two changes to a traditional CandyMachine UI:
Your UI must lookup a wallet's gateway token. For more details on gateway tokens, see the Civic Pass documentation.
Quickstart:
import {findGatewayToken} from "@identity.com/solana-gateway-ts";
const gatekeeperNetwork = new PublicKey("tgnuXXNMDLK8dy7Xm1TdeGyc95MDym4bvAQCwcW21Bf");
const foundToken = await findGatewayToken(connection, wallet.publicKey, gatekeeperNetwork);
If you want to integrate Civic's KYC flow into your UI, you can use Civic's react component.
More details here
import * as TokenGuard from "@civic/token-guard";
const tokenGuard = new PublicKey("<ID from step 1>")
const program = await TokenGuard.fetchProgram(provider)
const instructions = await TokenGuard.exchange(
connection,
program,
tokenGuard,
payer,
payer,
gatekeeperNetwork,
amount
);
await program.rpc.mintNft({
accounts: {
// ... candymachine accounts
},
remainingAccounts: remainingAccounts,
signers: [mint],
instructions: [
...(tokenGuardInstructions), // ADD THIS LINE
//...other candymachine instructions,
],
});
$ cargo install anchor
$ anchor build
$ anchor deploy
$ anchor idl init
Four factors mitigate against that:
Both are good options. In fact, if you prefer that model, we have forks for Metaplex CandyMachine and Auction contract that do that.
This option is potentially more flexible, as it can protect any kind of similar on-chain protocol, without requiring each protocol to change to validate gateway tokens.
TokenGuard support for SPL Token is in the roadmap.
This is where the beauty of the atomic Solana transaction model comes in. If the TokenGuard exchange and smart contract instructions are in the same transaction, and one fails, the whole thing is rolled back and the buyer does not lose Sol.
FAQs
Client SDK for the TokenGuard Solana program
We found that @civic/token-guard demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.