stubbed out transfer and metadata

This commit is contained in:
aresastro
2023-05-10 21:37:54 +08:00
parent 07f4d51c28
commit b9ac3bf408
4 changed files with 84 additions and 1 deletions

View File

@@ -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}`)
}

View File

@@ -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("<mint address>")
// 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}`)
}
})();

View File

@@ -16,7 +16,23 @@ const mint = new PublicKey("<mint address>");
(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}`)
}

View File

@@ -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("<mint address>");
// Recipient address
const to = new PublicKey("<receiver address>");
(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}`)
}
})();