1 unstable release
0.1.0 | Jun 6, 2024 |
---|
#57 in #anchor
120KB
3K
SLoC
PitchTalk Solana Contract
This is a PitchTalk contract for Solana blockchain.
Program
Dependencies
To install everything you need to work with this project, you'll need to install dependencies as described in Anchor documentation.
Build contract
The source code of pitchtalk program is in ./programs/pitchtalk-solana. To build the pitchtalk-solana program, you need to execute this command:
anchor build
You'll get the following output:
- program binaries at ./target/deploy/pitchtalk_solana.so
- IDL file at ./target/idl/pitchtalk_solana.json
- Typescript typings at ./target/types/pitchtalk_solana.ts
Deploy
To deploy the program, run this command:
anchor deploy \
--provider.cluster $ANCHOR_PROVIDER_URL \
--program-keypair $KEYPAIR \
--program-name pitchtalk_solana \
--provider.wallet $ANCHOR_WALLET
Run scripts
Before start setup env file with corresponding variables:
- ANCHOR_PROVIDER_URL - url of solana rpc
- ANCHOR_WALLET - path to wallet to sign transactions
- PITCHTALK_PROGRAM_ID - public key of PitchTalk program
- KEYPAIR - PitchTalk program account keypair
Available scripts:
- To initialize contract state run:
npm run initialize-state <DONATION_FEE> <GRANT_FEE> <INVESTMENT_FEE> <EVENT_FEE>
- To update contract state run:
npm run update-state <DONATION_FEE> <GRANT_FEE> <INVESTMENT_FEE> <EVENT_FEE>
- To create admin run:
npm run create-admin <ID> <ACCOUNT> <NAME>
- To update admin run:
npm run update-admin <ID> <ACCOUNT> <NAME>
- To remove admin run:
npm run remove-admin <ID>
- To add whitelist token run:
npm run add-whitelist-token <ADMIN_ID> <MINT> <DECIMALS> <AUTHORITY_ADDRESS>
Run tests
To test the pitchtalk-solana program, you need to execute this command:
./tests/test_script.sh
This command starts a local validator, sets up the program on chain and runs a suite of Jest tests against it.
Typescript client
The Javascript/Typescript client for this program.
It's published by this command:
npm publish
Please view the test suite (./tests/**.spec.ts) to see how can this client be used in NodeJS context.
Basic usage example
import { Connection, PublicKey } from "@solana/web3.js";
import { Provider } from "@coral-xyz/anchor";
import { PitchTalkProgram } from "@pitchtalk/pitchtalk-solana-cli";
// Setup web3 Connection
const connection = new Connection("https://api.mainnet-beta.solana.com");
// Use Phantom wallet provider
const wallet = window.solana;
// Setup Anchor provider
const provider = new Provider(connection, wallet as any);
// pitchtalk program ID is a well-known public key
const program = new PitchTalkProgram(
new web3.PublicKey(PITCH_TALK_ID),
provider
);
Dependencies
~18–27MB
~453K SLoC