-
ποΈ ticket reservation contract to buy ticket for the event
-
π₯ B2C whitelist contract to burn the past event roles for whitelist spots
Makre sure you have compatible version: solana-cli version: 1.16.1 | anchor version: 0.28.0
Make sure you have a setup solana wallet using
solana-keygen newcommand.
sudo chmod +x deploy.sh && ./deploy.sh - Generate a new keypair using
solana-keygen newcommand, the following sample output is important for us! We'll use this public key as the program authority to deploy the program with it.
Wrote new keypair to /Users/$USER/.config/solana/id.json
============================================================================
pubkey: DaWYunpuRDQfuaJXvmQssQYvqfkshx6P6dihRCzSLCcr
============================================================================
Save this seed phrase and your BIP39 passphrase to recover your new keypair:
conduct embark six chaos olympic harvest youth garbage tower jazz slow taste
============================================================================
-
You can extract the public key using
solana address -k /Users/$USER/.config/solana/id.jsoncommand. -
Change the
providerfield inside theAnchor.tomlfile with the proper path of the generated wallet address JSON.
-
Fire up a terminal and run a local ledger using
solana-test-validatorcommand. -
In the second terminal:
- config the solana on the localnet using
solana config set --url localhostcommand. - charge your generated wallet using
solana airdrop 10command or the faucet site for testnet or devnet. - build the contract with
anchor build --program-name ticketcommand. - deploy the contract on the localnet with
anchor deploy --program-name ticket - the output of the deploy command is something like:
Deploying workspace: http://localhost:8899 Upgrade authority: /Users/$USER/.config/solana/id.json Deploying program "ticket"... Program path: /Users/$USER/Documents/gem/conse/target/deploy/ticket.so... Program Id: bArDn16ERF32oHbL3Qvbsfz55xkj1CdbPV8VYXJtCtk Deploy success
- show the deployed program:
solana program show bArDn16ERF32oHbL3Qvbsfz55xkj1CdbPV8VYXJtCtkand the output sample would be like:in which the owner is the BPF loader which is the owner of every upgradable Solana program account, and the upgrade authority is the public key of the generated wallet info whom has deployed this contract.Program Id: bArDn16ERF32oHbL3Qvbsfz55xkj1CdbPV8VYXJtCtk Owner: BPFLoaderUpgradeab1e11111111111111111111111 ProgramData Address: Bq447TCGGXipjaVrQb72TVLrgzVVqD85FYcGDMZeGMgk Authority: 8SzHrPVkDf5xhmjyUJ7W8vDaxhTiGF9XBT9XX2PtiwYF Last Deployed In Slot: 477 Data Length: 671648 (0xa3fa0) bytes Balance: 4.67587416 SOL
- show the account info:
solana account bArDn16ERF32oHbL3Qvbsfz55xkj1CdbPV8VYXJtCtk - remember to change the program id in
declare_idinlib.rsand[programs.localnet][programs.mainnet],[programs.devnet]section, theticketfield inside theAnchor.tomlwith the deployed address of the contract or the Program Id which is the output of theanchor deploycommand; all mentioned three sections must have same public address of the deployed contract which is the wallet info inside the*-keypair.jsonin thetarget/deploydirectory. - also you can check the deployed contract address or the Program Id with
solana address -k target/deploy/ticket-keypair.jsoncommand.
- config the solana on the localnet using
-
In the second one run
anchor run test-ticketcommand, the output will be:conse-whitelist player 1 balance: 10000000000 sending sol from player to PDA >>>> player balance: 4999995000 >>>> PDA account balance: 5000000000 --------------------------------------------- after game results transfer... player balance after game: 4999995000 PDA account balance after game: 250000000 revenue share wallet account balance: 3500000000 --------------------------------------------- β Pda created! (1372ms) 1 passing (1s) Done in 3.27s.
-
change the
clusterfield under the[provider]section inside theAnchor.tomleither todevnet. -
solana config set --url devnet -
charge your generated wallet using
solana airdrop 10command or the faucet site for testnet or devnet. -
build the contract with
anchor build --program-name ticketcommand. -
deploy the contract on the localnet with
anchor deploy --program-name ticket -
the output of the deploy command is something like:
Deploying workspace: https://api.devnet.solana.com Upgrade authority: /Users/$USER/.config/solana/id.json Deploying program "ticket"... Program path: /Users/$USER/Documents/gem/conse/target/deploy/ticket.so... Program Id: bArDn16ERF32oHbL3Qvbsfz55xkj1CdbPV8VYXJtCtk Deploy success
-
show the deployed program:
solana program show bArDn16ERF32oHbL3Qvbsfz55xkj1CdbPV8VYXJtCtkand the output sample would be like:Program Id: bArDn16ERF32oHbL3Qvbsfz55xkj1CdbPV8VYXJtCtk Owner: BPFLoaderUpgradeab1e11111111111111111111111 ProgramData Address: Bq447TCGGXipjaVrQb72TVLrgzVVqD85FYcGDMZeGMgk Authority: 8SzHrPVkDf5xhmjyUJ7W8vDaxhTiGF9XBT9XX2PtiwYF Last Deployed In Slot: 477 Data Length: 671648 (0xa3fa0) bytes Balance: 4.67587416 SOL
in which the owner is the BPF loader which is the owner of every upgradable Solana program account, and the upgrade authority is the public key of the generated wallet info whom has deployed this contract.
-
show the account info:
solana account bArDn16ERF32oHbL3Qvbsfz55xkj1CdbPV8VYXJtCtk -
remember to change the program id in
declare_idinlib.rsand[programs.localnet][programs.mainnet],[programs.devnet]section, theticketfield inside theAnchor.tomlwith the deployed address of the contract or the Program Id which is the output of theanchor deploycommand; all mentioned three sections must have same public address of the deployed contract which is the wallet info inside the*-keypair.jsonin thetarget/deploydirectory.- also you can check the deployed contract address or the Program Id with
solana address -k target/deploy/ticket-keypair.jsoncommand.
- also you can check the deployed contract address or the Program Id with
-
once the program gets compiled successfully a keypair for the program will be generated inside
target/deploy/<PROGRAM_NAME>-keypair.jsonwhich contains the public key of the program and can be used to set the program id of the contract inside the code. -
Before running the deploy script make sure that you've installed the nodejs and also set the
clusterfield to themainnetor the address of your node on either devnet or mainnet like Alchemy node, inside theAnchor.tomlbesides change the solana cluster usingsolana config set --url mainnetorsolana config set --url <CUSTOM_RPC_ENDPOINT>also make sure that your account has enough balance for deploying the program. -
once the authority gets changed the program id will be changed too, currently these programs are authorized with
8SzHrPVkDf5xhmjyUJ7W8vDaxhTiGF9XBT9XX2PtiwYF -
use
anchor keys listto list all the program ids of each contract. -
if you get error
"*/tsconfig.json" needs an import assertion of type jsonjust inside theconsefolder typeyarn add ts-mocha. -
to test the whitelist contract run
anchor run test-whitelist, just to make sure you have a test validator up and running on your localnet in another terminal. -
currently the program id of the whitelist contract is
2YQmwuktcWmmhXXAzjizxzie3QWEkZC8HQ4ZnRtrKF7p. -
every time we start a the local node using
solana-test-validatorit search for the existingtest-ledgerfolder and if it's not there it'll create a new one, note that in this stage we must deploy the program again to be known by the newly runtime of the local node. -
currently the program will be deployed on devnet, if you want to deploy on another network just change the
clusterfield under the[provider]section inside theAnchor.tomleither tomainnet,testnetor your node address. -
after running
anchor buildfor the first time a newkeypair.jsonwill be generated which contains the wallet info the public and private key of the deployed contract in which the program id is the base58 encoded public key address of the deployed contract. -
use
anchor init NEW_ANCHOR_PROJECTto build a new anchor workspace,anchor new PROGRAM_NAMEto create a new program in the workspace,anchor build --program-name PROGRAM_NAMEandanchor deploy --program-name PROGRAM_NAMEto build and deploy the specified program. -
the steps to build and deploy the whitelist contract is the same as the ticket contract, simply run
anchor build --program-name whitelistand thenanchor build --program-name whitelist. -
solana balanceshows the balance of the address inside the/Users/$USER/.config/solana/id.jsonon the selected network which is one of thedevnet,testnetorlocalhost.