|
@@ -1,5 +1,5 @@
|
|
|
import * as anchor from "@project-serum/anchor";
|
|
|
-import { Mint2 } from "../target/types/mint_2";
|
|
|
+import { CreateToken } from "../target/types/create_token";
|
|
|
|
|
|
|
|
|
const TOKEN_METADATA_PROGRAM_ID = new anchor.web3.PublicKey(
|
|
@@ -7,21 +7,21 @@ const TOKEN_METADATA_PROGRAM_ID = new anchor.web3.PublicKey(
|
|
|
);
|
|
|
|
|
|
|
|
|
-describe("mint-token", () => {
|
|
|
+describe("Create an SPL Token", () => {
|
|
|
|
|
|
const provider = anchor.AnchorProvider.env();
|
|
|
anchor.setProvider(provider);
|
|
|
const payer = provider.wallet as anchor.Wallet;
|
|
|
- const program = anchor.workspace.Mint2 as anchor.Program<Mint2>;
|
|
|
+ const program = anchor.workspace.CreateToken as anchor.Program<CreateToken>;
|
|
|
|
|
|
- const testTokenTitle = "Solana Gold";
|
|
|
- const testTokenSymbol = "GOLDSOL";
|
|
|
- const testTokenUri = "https://raw.githubusercontent.com/solana-developers/program-examples/main/tokens/mint-2/anchor/tests/token_metadata.json";
|
|
|
+ const tokenTitle = "Solana Gold";
|
|
|
+ const tokenSymbol = "GOLDSOL";
|
|
|
+ const tokenUri = "https://raw.githubusercontent.com/solana-developers/program-examples/new-examples/tokens/tokens/.assets/spl-token.json";
|
|
|
|
|
|
const mintKeypair: anchor.web3.Keypair = anchor.web3.Keypair.generate();
|
|
|
console.log(`New token: ${mintKeypair.publicKey}`);
|
|
|
|
|
|
- it("Create the mint", async () => {
|
|
|
+ it("Create!", async () => {
|
|
|
|
|
|
const [mintAuthorityPda, mintAuthorityPdaBump] = await anchor.web3.PublicKey.findProgramAddress(
|
|
|
[
|
|
@@ -40,136 +40,24 @@ describe("mint-token", () => {
|
|
|
TOKEN_METADATA_PROGRAM_ID
|
|
|
))[0];
|
|
|
|
|
|
- await program.methods.createTokenMint(
|
|
|
- testTokenTitle, testTokenSymbol, testTokenUri, mintAuthorityPdaBump
|
|
|
+ const sx = await program.methods.createTokenMint(
|
|
|
+ tokenTitle, tokenSymbol, tokenUri
|
|
|
)
|
|
|
- .accounts({
|
|
|
- metadataAccount: metadataAddress,
|
|
|
- mintAccount: mintKeypair.publicKey,
|
|
|
- mintAuthority: mintAuthorityPda,
|
|
|
- payer: payer.publicKey,
|
|
|
- rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
|
- systemProgram: anchor.web3.SystemProgram.programId,
|
|
|
- tokenProgram: anchor.utils.token.TOKEN_PROGRAM_ID,
|
|
|
- tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
|
|
|
- })
|
|
|
- .signers([mintKeypair, payer.payer])
|
|
|
- .rpc();
|
|
|
- });
|
|
|
-
|
|
|
- it("Mint to your wallet!", async () => {
|
|
|
-
|
|
|
- const [mintAuthorityPda, mintAuthorityPdaBump] = await anchor.web3.PublicKey.findProgramAddress(
|
|
|
- [
|
|
|
- Buffer.from("mint_authority_"),
|
|
|
- mintKeypair.publicKey.toBuffer(),
|
|
|
- ],
|
|
|
- program.programId,
|
|
|
- );
|
|
|
-
|
|
|
- const amountToMint = 1;
|
|
|
-
|
|
|
- const tokenAddress = await anchor.utils.token.associatedAddress({
|
|
|
- mint: mintKeypair.publicKey,
|
|
|
- owner: payer.publicKey
|
|
|
- });
|
|
|
- console.log(`Token Address: ${tokenAddress}`);
|
|
|
-
|
|
|
- await program.methods.mintToYourWallet(
|
|
|
- new anchor.BN(amountToMint), mintAuthorityPdaBump
|
|
|
- )
|
|
|
- .accounts({
|
|
|
- mintAccount: mintKeypair.publicKey,
|
|
|
- mintAuthority: mintAuthorityPda,
|
|
|
- tokenAccount: tokenAddress,
|
|
|
- payer: payer.publicKey,
|
|
|
- rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
|
- systemProgram: anchor.web3.SystemProgram.programId,
|
|
|
- tokenProgram: anchor.utils.token.TOKEN_PROGRAM_ID,
|
|
|
- associatedTokenProgram: anchor.utils.token.ASSOCIATED_PROGRAM_ID,
|
|
|
- })
|
|
|
- .signers([payer.payer])
|
|
|
- .rpc();
|
|
|
- });
|
|
|
-
|
|
|
- it("Mint to another person's wallet (airdrop)!", async () => {
|
|
|
-
|
|
|
- const recipientKeypair = anchor.web3.Keypair.generate();
|
|
|
- await provider.connection.confirmTransaction(
|
|
|
- await provider.connection.requestAirdrop(recipientKeypair.publicKey, 1 * anchor.web3.LAMPORTS_PER_SOL)
|
|
|
- );
|
|
|
- console.log(`Recipient pubkey: ${recipientKeypair.publicKey}`);
|
|
|
-
|
|
|
- const [mintAuthorityPda, mintAuthorityPdaBump] = await anchor.web3.PublicKey.findProgramAddress(
|
|
|
- [
|
|
|
- Buffer.from("mint_authority_"),
|
|
|
- mintKeypair.publicKey.toBuffer(),
|
|
|
- ],
|
|
|
- program.programId,
|
|
|
- );
|
|
|
-
|
|
|
- const amountToMint = 1;
|
|
|
-
|
|
|
- const tokenAddress = await anchor.utils.token.associatedAddress({
|
|
|
- mint: mintKeypair.publicKey,
|
|
|
- owner: recipientKeypair.publicKey
|
|
|
- });
|
|
|
- console.log(`Token Address: ${tokenAddress}`);
|
|
|
-
|
|
|
- await program.methods.mintToAnotherWallet(
|
|
|
- new anchor.BN(amountToMint), mintAuthorityPdaBump
|
|
|
- )
|
|
|
- .accounts({
|
|
|
- mintAccount: mintKeypair.publicKey,
|
|
|
- mintAuthority: mintAuthorityPda,
|
|
|
- recipient: recipientKeypair.publicKey,
|
|
|
- tokenAccount: tokenAddress,
|
|
|
- payer: payer.publicKey,
|
|
|
- rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
|
- systemProgram: anchor.web3.SystemProgram.programId,
|
|
|
- tokenProgram: anchor.utils.token.TOKEN_PROGRAM_ID,
|
|
|
- associatedTokenProgram: anchor.utils.token.ASSOCIATED_PROGRAM_ID,
|
|
|
- })
|
|
|
- .signers([payer.payer])
|
|
|
- .rpc();
|
|
|
- });
|
|
|
-
|
|
|
- it("Transfer to another person's wallet!", async () => {
|
|
|
-
|
|
|
- const recipientWallet = anchor.web3.Keypair.generate();
|
|
|
- await provider.connection.confirmTransaction(
|
|
|
- await provider.connection.requestAirdrop(recipientWallet.publicKey, 2 * anchor.web3.LAMPORTS_PER_SOL)
|
|
|
- );
|
|
|
- console.log(`Recipient Pubkey: ${recipientWallet.publicKey}`);
|
|
|
-
|
|
|
- const amountToTransfer = 1;
|
|
|
-
|
|
|
- const ownerTokenAddress = await anchor.utils.token.associatedAddress({
|
|
|
- mint: mintKeypair.publicKey,
|
|
|
- owner: payer.publicKey
|
|
|
- });
|
|
|
- console.log(`Owner Token Address: ${ownerTokenAddress}`);
|
|
|
- const recipientTokenAddress = await anchor.utils.token.associatedAddress({
|
|
|
- mint: mintKeypair.publicKey,
|
|
|
- owner: recipientWallet.publicKey
|
|
|
- });
|
|
|
- console.log(`Recipient Token Address: ${recipientTokenAddress}`);
|
|
|
-
|
|
|
- await program.methods.transferToAnotherWallet(
|
|
|
- new anchor.BN(amountToTransfer)
|
|
|
- )
|
|
|
- .accounts({
|
|
|
- mintAccount: mintKeypair.publicKey,
|
|
|
- ownerTokenAccount: ownerTokenAddress,
|
|
|
- recipientTokenAccount: recipientTokenAddress,
|
|
|
- owner: payer.publicKey,
|
|
|
- recipient: recipientWallet.publicKey,
|
|
|
- rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
|
- systemProgram: anchor.web3.SystemProgram.programId,
|
|
|
- tokenProgram: anchor.utils.token.TOKEN_PROGRAM_ID,
|
|
|
- associatedTokenProgram: anchor.utils.token.ASSOCIATED_PROGRAM_ID,
|
|
|
- })
|
|
|
- .signers([payer.payer])
|
|
|
- .rpc();
|
|
|
+ .accounts({
|
|
|
+ metadataAccount: metadataAddress,
|
|
|
+ mintAccount: mintKeypair.publicKey,
|
|
|
+ mintAuthority: mintAuthorityPda,
|
|
|
+ payer: payer.publicKey,
|
|
|
+ rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
|
+ systemProgram: anchor.web3.SystemProgram.programId,
|
|
|
+ tokenProgram: anchor.utils.token.TOKEN_PROGRAM_ID,
|
|
|
+ tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
|
|
|
+ })
|
|
|
+ .signers([mintKeypair, payer.payer])
|
|
|
+ .rpc();
|
|
|
+
|
|
|
+ console.log("Success!");
|
|
|
+ console.log(` Mint Address: ${mintKeypair.publicKey}`);
|
|
|
+ console.log(` Tx Signature: ${sx}`);
|
|
|
});
|
|
|
});
|