From b9ac3bf40828367a552bc8b395071bfdb92d2561 Mon Sep 17 00:00:00 2001 From: aresastro Date: Wed, 10 May 2023 21:37:54 +0800 Subject: [PATCH] stubbed out transfer and metadata --- ts/cluster1/spl_init.ts | 7 +++++++ ts/cluster1/spl_metadata.ts | 32 ++++++++++++++++++++++++++++++++ ts/cluster1/spl_mint.ts | 18 +++++++++++++++++- ts/cluster1/spl_transfer.ts | 28 ++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/ts/cluster1/spl_init.ts b/ts/cluster1/spl_init.ts index be0154e..ab882a4 100644 --- a/ts/cluster1/spl_init.ts +++ b/ts/cluster1/spl_init.ts @@ -12,6 +12,13 @@ const connection = new Connection("https://api.devnet.solana.com", commitment); (async () => { try { // Start here + const mint = await createMint( + connection, + keypair, + keypair.publicKey, + null, + 6 + ) } catch(error) { console.log(`Oops, something went wrong: ${error}`) } diff --git a/ts/cluster1/spl_metadata.ts b/ts/cluster1/spl_metadata.ts index e69de29..fdc7d52 100644 --- a/ts/cluster1/spl_metadata.ts +++ b/ts/cluster1/spl_metadata.ts @@ -0,0 +1,32 @@ +import { Commitment, Connection, Keypair, PublicKey, Transaction, sendAndConfirmTransaction } from "@solana/web3.js" +import wallet from "../wba-wallet.json" +import { createCreateMetadataAccountV2Instruction, createCreateMetadataAccountV3Instruction } from "@metaplex-foundation/mpl-token-metadata"; + +// We're going to import our keypair from the wallet file +const keypair = Keypair.fromSecretKey(new Uint8Array(wallet)); + +//Create a Solana devnet connection +const commitment: Commitment = "confirmed"; +const connection = new Connection("https://api.devnet.solana.com", commitment); + +// Define our Mint address +const mint = new PublicKey("") + +// Add the Token Metadata Program +const token_metadata_program_id = new PublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s') + +// Create PDA for token metadata +const metadata_seeds = [ + Buffer.from('metadata'), + token_metadata_program_id.toBuffer(), + mint.toBuffer(), +]; +const [metadata_pda, _bump] = PublicKey.findProgramAddressSync(metadata_seeds, token_metadata_program_id); + +(async () => { + try { + // Start here + } catch(e) { + console.error(`Oops, something went wrong: ${e}`) + } +})(); \ No newline at end of file diff --git a/ts/cluster1/spl_mint.ts b/ts/cluster1/spl_mint.ts index 7c9e7ff..07c48fb 100644 --- a/ts/cluster1/spl_mint.ts +++ b/ts/cluster1/spl_mint.ts @@ -16,7 +16,23 @@ const mint = new PublicKey(""); (async () => { try { - // Start here + const ata = await getOrCreateAssociatedTokenAccount( + connection, + keypair, + mint, + keypair.publicKey + ); + console.log(`Your ata is: ${ata.address.toBase58()}`); + + const mintTx = await mintTo( + connection, + keypair, + mint, + ata.address, + keypair, + 1000n * token_decimals + ) + console.log(`Your mint txid: ${mintTx}`); } catch(error) { console.log(`Oops, something went wrong: ${error}`) } diff --git a/ts/cluster1/spl_transfer.ts b/ts/cluster1/spl_transfer.ts index e69de29..fcffec9 100644 --- a/ts/cluster1/spl_transfer.ts +++ b/ts/cluster1/spl_transfer.ts @@ -0,0 +1,28 @@ +import { Commitment, Connection, Keypair, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js" +import wallet from "../wba-wallet.json" +import { getOrCreateAssociatedTokenAccount, transfer } from "@solana/spl-token"; + +// We're going to import our keypair from the wallet file +const keypair = Keypair.fromSecretKey(new Uint8Array(wallet)); + +//Create a Solana devnet connection +const commitment: Commitment = "confirmed"; +const connection = new Connection("https://api.devnet.solana.com", commitment); + +// Mint address +const mint = new PublicKey(""); + +// Recipient address +const to = new PublicKey(""); + +(async () => { + try { + // Get the token account of the fromWallet address, and if it does not exist, create it + + // Get the token account of the toWallet address, and if it does not exist, create it + + // Transfer the new token to the "toTokenAccount" we just created + } catch(e) { + console.error(`Oops, something went wrong: ${e}`) + } +})(); \ No newline at end of file