A program that lets other smart contracts manage access to an on-chain Solana service. It supports addition, removal of wallets to a whitelist, and grants the ability to checking if a wallet is whitelisted.
The whitelisting contract works using pdas. When a wallet is added to the whitelist a new account with a PDA is created for it. Hence to know if a wallet is whitelisted or not all we'd to do is check if the account that should have been created when it was added actually exists.
This program lives on the devnet at HqBtRNgYEFDDCiDh2jvt33MA9ZkC1hs59eQ5GLR3TfEu
- authority
The creator of the whitelist. - whitelist_pda
The whitelist account. - wallet_pda
A PDA with seeds:[whitelist.key(), wallet_address.key()]
.wallet_address
is the address of a wallet that's to be whitelisted or expected to already be.
create_whitelist()
Accounts:
- authority
(mut, signer)
The whitelist authority and signer of this instruction. - whitelist
Your to-be-created whitelist account. - system_program
The Solana system program account.
add_wallet(wallet_address)
Arguments:
- wallet_address
The public key of the wallet to be added.
Accounts:
- authority
(mut, signer)
The whitelist authority - whitelist
(mut)
The whitelist account. - wallet_pda
Awallet_pda
account with seeds:[whitelist.key(), wallet_address.key()]
. - sytem_program
The Solana system program account.
check_wallet(wallet_address)
Arguments:
- wallet_address
The public key of the wallet to be added.
Accounts:
- whitelist
The whitelist. - wallet_pda
Awallet_pda
account with the specified seeds.
remove_wallet(wallet_address)
Arguments:
- wallet_address
The public key of the wallet to be added.
Accounts:
- authority
(mut, signer)
The whitelist authority. - whitelist
(mut)
The whitelist account. - wallet_pda
(mut)
Awallet_pda
account with the specified seeds.
pub fun set_authority(new_authority)
Arguments:
- new_authority
The new authority of the whitelist.
Accounts:
- authority
(signer)
The whitelist authority. - whitelist
(mut)
The whitelist account.
View the full steps here.
- Run
solana-keygen new
to create a wallet keypair - Run
solana airdrop 2
to airdrop sol to your wallet
- Clone the repo and change into its root directory
- Run
anchor build
to generate a new public key for your program - Run
anchor keys list
. Copy the new pubkey into your declare_id! macro at the top oflib.rs
and replace the default key inAnchor.toml
- Change the
provider.cluster
variable inAnchor.toml
todevnet
- Run
anchor deploy
- Run
anchor run test