- Install Rust development environment (see [https://www.rust-lang.org/tools/install]).
- Install Solana SDK and other tools (see [https://docs.solana.com/ru/cli/install-solana-cli-tools]).
- Install NodeJs.
- From the folder /user-account/program/, run
cargo build-bpf - (optional) From the folder /user-account/program/, run
cargo test-bpfto make sure that all the automatic tests passed successfully - Make sure you have enough balance to deploy the program. For this purpose, run
solana balance. NOTE: If you're in a dev, or test mode you can refill your balance runningsolana airdrop 1as many times as you need. - To deploy this program, run
solana program deploy <an absolute path to the local repository>/user-account/program/target/deploy/emotion_user_account.so. Save the program id for further use.
- To create a new token run
spl-token create-token. Save the token address for further use. - Open and edit /user-account/js/config.ts. Set the values for
PROGRAM_IDandMINT_IDvariables to the program id and token address correspondingly (see the recent steps). - From the folder /user-account/js/, run
npm install - Create an associated token account for your current wallet with this command
spl-token create-account <TOKEN_ADDRESS> - Mint the required amount of tokens to your wallet with this command
spl-token mint <TOKEN_ADDRESS> <AMOUNT>. - Create a source account for the program on behalf of your wallet. A source account serves as the custodial for all the users' tokens and are used to withdraw the tokens from the program to the users' wallets. To create this account, run the command
npm run create-account 0from the folder /user-account/js/. Save the source account address for further use. - Top-up the balance of the source account. To do so, you have to transfer the tokens from your current wallet to this account. It can be done with this command
spl-token transfer <TOKEN_ADDRESS> <AMOUNT> <SOURCE_ACCOUNT_ADDRESS> --fund-recipient.
The program supports the following instructions:
- Create a new user account
npm run create-account <user_id> - Deposit
npm run deposit-account <user_id> <amount> - Withdraw
npm run withdraw-account <user_id> <amount> - Transfer
npm run transfer <sender_id> <recipient_id> <amount> - Block
npm run block-account <user_id> <amount> - Unblock
npm run unblock-account <user_id> <amount>