In order to initialize the account, we are creating a struct that made of the mint account (of type mint), a signer (the payer will sign the creation), system_program, token_program and rent.
To transfer the tokens, we are creating a struct made of the token_program, the ATA (associated token account) that we are transferring the token from and the ATA that will receive the tokens as well as the authority of the ATA that transfers the tokens.
We are importing from anchor_spl, so this dependency had to be added to package.json.
We are also importing from @solana/spl-token, which needed to be installed.
Testing
Testing did not go very well. I believe the problem is I am missing something on the test side, not on the rust side.
I tried to test it in 2 ways (both test files can be found in the test folder):
First, I tried to initialize the mint account through a transaction, then get the ATA for the account and mint tokens there (this test is in the file named test_project2_alt.ts). This resulted in the following error: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 2: insufficient account keys for instruction
Second, I tried to do it as shown in the test file named test_project2.ts, which resulted in the following error: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction
Changes
Implementation Details
Testing
Testing did not go very well. I believe the problem is I am missing something on the test side, not on the rust side.
I tried to test it in 2 ways (both test files can be found in the test folder):