From 8f40262b0f6c6cc3cff6d568d88f5e89451c6463 Mon Sep 17 00:00:00 2001 From: Unclephil Date: Tue, 21 May 2024 20:32:29 +0100 Subject: [PATCH 1/4] solana day 2 --- ReadData/writingSol.ts | 49 +++++++++++++++++++++++ Reading/esrun-1716146495187.tmp.mjs | 33 +++++++++++++++ Reading/phil.ts | 28 +++++++++++++ Unclephil.md | 12 ++++++ Writing/main.ts | 2 +- Writing/phil.ts | 62 +++++++++++++++++++++++++++++ 6 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 ReadData/writingSol.ts create mode 100644 Reading/esrun-1716146495187.tmp.mjs create mode 100644 Reading/phil.ts create mode 100644 Unclephil.md create mode 100644 Writing/phil.ts diff --git a/ReadData/writingSol.ts b/ReadData/writingSol.ts new file mode 100644 index 0000000..7bf0c1a --- /dev/null +++ b/ReadData/writingSol.ts @@ -0,0 +1,49 @@ +import { + Connection, + Transaction, + SystemProgram, + sendAndConfirmTransaction, + PublicKey, + } from "@solana/web3.js"; + import "dotenv/config" + import { getKeypairFromEnvironment } from "@solana-developers/helpers"; + + const suppliedToPubkey = process.argv[2] || null; + + if (!suppliedToPubkey) { + console.log(`Please provide a public key to send to`); + process.exit(1); + } + + const senderKeypair = getKeypairFromEnvironment("SECRET_KEY"); + + console.log(`suppliedToPubkey: ${suppliedToPubkey}`); + + const toPubkey = new PublicKey(suppliedToPubkey); + + const connection = new Connection("https://api.devnet.solana.com", "confirmed"); + + console.log( + `✅ Loaded our own keypair, the destination public key, and connected to Solana` + ); + + const transaction = new Transaction(); + + const LAMPORTS_TO_SEND = 5000; + + const sendSolInstruction = SystemProgram.transfer({ + fromPubkey: senderKeypair.publicKey, + toPubkey, + lamports: LAMPORTS_TO_SEND, + }); + + transaction.add(sendSolInstruction); + + const signature = await sendAndConfirmTransaction(connection, transaction, [ + senderKeypair, + ]); + + console.log( + `💸 Finished! Sent ${LAMPORTS_TO_SEND} to the address ${toPubkey}. ` + ); + console.log(`Transaction signature is ${signature}!`); \ No newline at end of file diff --git a/Reading/esrun-1716146495187.tmp.mjs b/Reading/esrun-1716146495187.tmp.mjs new file mode 100644 index 0000000..d041fcb --- /dev/null +++ b/Reading/esrun-1716146495187.tmp.mjs @@ -0,0 +1,33 @@ +process.argv = [process.argv[0], ...process.argv.slice(3)]; + + import __esrun_url from 'url'; + + import { createRequire as __esrun_createRequire } from "module"; + + const __esrun_fileUrl = __esrun_url.pathToFileURL("esrun-1716146495187.tmp.mjs"); + + const require = __esrun_createRequire(__esrun_fileUrl); +// phil.ts +import { Connection, PublicKey, clusterApiUrl, LAMPORTS_PER_SOL } from "../node_modules/@solana/web3.js/lib/index.cjs.js"; +(async () => { + const connection = new Connection(clusterApiUrl("devnet")); + const addressString = "xrwPFQEZCqFwLjtQC8Xg2FPPaoAh6enjE8ZG6Gj7gr5"; + let address; + try { + address = new PublicKey(addressString); + } catch (e) { + console.error(`Invalid public key provided: ${addressString}`); + process.exit(1); + } + try { + const balance = await connection.getBalance(address); + const balanceInSol = balance / LAMPORTS_PER_SOL; + console.log(`The balance of the account at ${address} is ${balanceInSol} SOL`); + console.log(`\u2705 Finished!`); + } catch (error) { + console.error(`Failed to fetch balance: ${error.message}`); + } +})(); +//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsicGhpbC50cyJdLAogICJzb3VyY2VSb290IjogIkM6XFxVc2Vyc1xccGhpbGlcXE9uZURyaXZlXFxEZXNrdG9wXFxQcm9qZWN0XFxGdWxsc3RhY2tcXDMwLURheXMtU29sYW5hLURldmVsb3Blci1Cb290Y2FtcFxcUmVhZGluZyIsCiAgInNvdXJjZXNDb250ZW50IjogWyJpbXBvcnQgeyBDb25uZWN0aW9uLCBQdWJsaWNLZXksIGNsdXN0ZXJBcGlVcmwsIExBTVBPUlRTX1BFUl9TT0wgfSBmcm9tIFwiQHNvbGFuYS93ZWIzLmpzXCI7XHJcblxyXG4oYXN5bmMgKCkgPT4ge1xyXG4gIGNvbnN0IGNvbm5lY3Rpb24gPSBuZXcgQ29ubmVjdGlvbihjbHVzdGVyQXBpVXJsKFwiZGV2bmV0XCIpKTtcclxuICBjb25zdCBhZGRyZXNzU3RyaW5nID0gJ3hyd1BGUUVaQ3FGd0xqdFFDOFhnMkZQUGFvQWg2ZW5qRThaRzZHajdncjUnO1xyXG4gIFxyXG4gIGxldCBhZGRyZXNzO1xyXG4gIHRyeSB7XHJcbiAgICBhZGRyZXNzID0gbmV3IFB1YmxpY0tleShhZGRyZXNzU3RyaW5nKTtcclxuICB9IGNhdGNoIChlKSB7XHJcbiAgICBjb25zb2xlLmVycm9yKGBJbnZhbGlkIHB1YmxpYyBrZXkgcHJvdmlkZWQ6ICR7YWRkcmVzc1N0cmluZ31gKTtcclxuICAgIHByb2Nlc3MuZXhpdCgxKTtcclxuICB9XHJcblxyXG4gIHRyeSB7XHJcbiAgICBjb25zdCBiYWxhbmNlID0gYXdhaXQgY29ubmVjdGlvbi5nZXRCYWxhbmNlKGFkZHJlc3MpO1xyXG4gICAgY29uc3QgYmFsYW5jZUluU29sID0gYmFsYW5jZSAvIExBTVBPUlRTX1BFUl9TT0w7XHJcblxyXG4gICAgY29uc29sZS5sb2coYFRoZSBiYWxhbmNlIG9mIHRoZSBhY2NvdW50IGF0ICR7YWRkcmVzc30gaXMgJHtiYWxhbmNlSW5Tb2x9IFNPTGApO1xyXG4gICAgY29uc29sZS5sb2coYFx1MjcwNSBGaW5pc2hlZCFgKTtcclxuICB9IGNhdGNoIChlcnJvcikge1xyXG4gICAgY29uc29sZS5lcnJvcihgRmFpbGVkIHRvIGZldGNoIGJhbGFuY2U6ICR7ZXJyb3IubWVzc2FnZX1gKTtcclxuICB9XHJcbn0pKCk7XHJcbiJdLAogICJtYXBwaW5ncyI6ICI7QUFBQSxTQUFTLFlBQVksV0FBVyxlQUFlLHdCQUF3QjtBQUFBLENBRXRFLFlBQVk7QUFDWCxRQUFNLGFBQWEsSUFBSSxXQUFXLGNBQWMsUUFBUSxDQUFDO0FBQ3pELFFBQU0sZ0JBQWdCO0FBRXRCLE1BQUk7QUFDSixNQUFJO0FBQ0YsY0FBVSxJQUFJLFVBQVUsYUFBYTtBQUFBLEVBQ3ZDLFNBQVMsR0FBUDtBQUNBLFlBQVEsTUFBTSxnQ0FBZ0MsZUFBZTtBQUM3RCxZQUFRLEtBQUssQ0FBQztBQUFBLEVBQ2hCO0FBRUEsTUFBSTtBQUNGLFVBQU0sVUFBVSxNQUFNLFdBQVcsV0FBVyxPQUFPO0FBQ25ELFVBQU0sZUFBZSxVQUFVO0FBRS9CLFlBQVEsSUFBSSxpQ0FBaUMsY0FBYyxrQkFBa0I7QUFDN0UsWUFBUSxJQUFJLGtCQUFhO0FBQUEsRUFDM0IsU0FBUyxPQUFQO0FBQ0EsWUFBUSxNQUFNLDRCQUE0QixNQUFNLFNBQVM7QUFBQSxFQUMzRDtBQUNGLEdBQUc7IiwKICAibmFtZXMiOiBbXQp9Cg== + + \ No newline at end of file diff --git a/Reading/phil.ts b/Reading/phil.ts new file mode 100644 index 0000000..9c3aabe --- /dev/null +++ b/Reading/phil.ts @@ -0,0 +1,28 @@ +import { Connection, PublicKey, clusterApiUrl, LAMPORTS_PER_SOL } from "@solana/web3.js"; + +(async () => { + const connection = new Connection(clusterApiUrl("devnet")); + const addressString = 'xrwPFQEZCqFwLjtQC8Xg2FPPaoAh6enjE8ZG6Gj7gr5'; + + let address; + try { + address = new PublicKey(addressString); + if (!PublicKey.isOnCurve(address.toBuffer())) { + throw new Error('The public key is off-curve, which indicates it is not a valid standard address.'); + } + } catch (e) { + console.error(`Invalid public key provided: ${addressString}`); + console.error(e.message); + process.exit(1); + } + + try { + const balance = await connection.getBalance(address); + const balanceInSol = balance / LAMPORTS_PER_SOL; + + console.log(`The balance of the account at ${address} is ${balanceInSol} SOL`); + console.log(`✅ Finished!`); + } catch (error) { + console.error(`Failed to fetch balance: ${error.message}`); + } +})(); diff --git a/Unclephil.md b/Unclephil.md new file mode 100644 index 0000000..aa2530b --- /dev/null +++ b/Unclephil.md @@ -0,0 +1,12 @@ +Que: Can the transaction be found on Explorer.solana.com? +Ans: Yes, It can. + +Que: How much SOL was transferred in the transaction? +Ans: The transaction transferred 0.1 SOL tokens. + +Que: How long does a transfer take? +Ans: The transfer takes approximately 0 - 2 minutes to complete. + +Que: What do you think "Confirm" means in this context? +Ans: "Confirm" means that the transaction has been processed and is now confirmed. + \ No newline at end of file diff --git a/Writing/main.ts b/Writing/main.ts index 7bf0c1a..1eec6d0 100644 --- a/Writing/main.ts +++ b/Writing/main.ts @@ -15,7 +15,7 @@ import { process.exit(1); } - const senderKeypair = getKeypairFromEnvironment("SECRET_KEY"); + const senderKeypair = getKeypairFromEnvironment("SOLANA_SECRET_KEY"); console.log(`suppliedToPubkey: ${suppliedToPubkey}`); diff --git a/Writing/phil.ts b/Writing/phil.ts new file mode 100644 index 0000000..208f8e6 --- /dev/null +++ b/Writing/phil.ts @@ -0,0 +1,62 @@ +import { + Connection, + Transaction, + SystemProgram, + sendAndConfirmTransaction, + PublicKey, + } from "@solana/web3.js"; + import "dotenv/config"; + import { getKeypairFromEnvironment } from "@solana-developers/helpers"; + + const suppliedToPubkey = process.argv[2] || null; + + if (!suppliedToPubkey) { + console.log(`Please provide a public key to send to`); + process.exit(1); + } + + let toPubkey; + try { + toPubkey = new PublicKey(suppliedToPubkey); + } catch (e) { + console.error(`Invalid public key provided: ${suppliedToPubkey}`); + process.exit(1); + } + + const senderKeypair = getKeypairFromEnvironment("SOLANA_SECRET_KEY"); + + if (!senderKeypair) { + console.error(`Failed to load sender's keypair from environment variable.`); + process.exit(1); + } + + const connection = new Connection("https://api.devnet.solana.com", "confirmed"); + + console.log( + `✅ Loaded our own keypair, the destination public key, and connected to Solana` + ); + + const transaction = new Transaction(); + const LAMPORTS_TO_SEND = 5000; + + const sendSolInstruction = SystemProgram.transfer({ + fromPubkey: senderKeypair.publicKey, + toPubkey, + lamports: LAMPORTS_TO_SEND, + }); + + transaction.add(sendSolInstruction); + + try { + const signature = await sendAndConfirmTransaction(connection, transaction, [ + senderKeypair, + ]); + + console.log( + `💸 Finished! Sent ${LAMPORTS_TO_SEND} lamports to the address ${toPubkey}.` + ); + console.log(`Transaction signature is ${signature}!`); + } catch (error) { + console.error(`Failed to send transaction: ${error.message}`); + } + \ No newline at end of file From 8763ec64c2fac98c1a1b08ea7babc653921e42bf Mon Sep 17 00:00:00 2001 From: Unclephil Date: Thu, 23 May 2024 14:00:23 +0100 Subject: [PATCH 2/4] Create Tokens With The Token Program --- Token-Program/tokenMint.ts | 2 +- Token-Program/transferToken.ts | 2 +- UnclePhil-SPL/metadata.ts | 100 +++++++++++++++++++++++++++++++++ UnclePhil-SPL/mint.ts | 47 ++++++++++++++++ UnclePhil-SPL/tokenAccount.ts | 50 +++++++++++++++++ UnclePhil-SPL/tokenMint.ts | 40 +++++++++++++ UnclePhil-SPL/tokenTransfer.ts | 53 +++++++++++++++++ package-lock.json | 6 -- package.json | 2 +- 9 files changed, 293 insertions(+), 9 deletions(-) create mode 100644 UnclePhil-SPL/metadata.ts create mode 100644 UnclePhil-SPL/mint.ts create mode 100644 UnclePhil-SPL/tokenAccount.ts create mode 100644 UnclePhil-SPL/tokenMint.ts create mode 100644 UnclePhil-SPL/tokenTransfer.ts diff --git a/Token-Program/tokenMint.ts b/Token-Program/tokenMint.ts index 6769993..90e1bdb 100644 --- a/Token-Program/tokenMint.ts +++ b/Token-Program/tokenMint.ts @@ -14,4 +14,4 @@ const tokenMint = await createMint(connection, user, user.publicKey, user.public const link = getExplorerLink("address", tokenMint.toString(), "devnet"); -console.log(`Token mint created! ${link}`); +console.log(`Token mint created! ${link}`); \ No newline at end of file diff --git a/Token-Program/transferToken.ts b/Token-Program/transferToken.ts index 983a0f5..ebd455a 100644 --- a/Token-Program/transferToken.ts +++ b/Token-Program/transferToken.ts @@ -49,4 +49,4 @@ async function transferToken() { } } -transferToken(); +transferToken(); \ No newline at end of file diff --git a/UnclePhil-SPL/metadata.ts b/UnclePhil-SPL/metadata.ts new file mode 100644 index 0000000..58f6231 --- /dev/null +++ b/UnclePhil-SPL/metadata.ts @@ -0,0 +1,100 @@ +import "dotenv/config"; +import { + getKeypairFromEnvironment, + getExplorerLink, +} from "@solana-developers/helpers"; +import { + Connection, + clusterApiUrl, + PublicKey, + Transaction, + sendAndConfirmTransaction, +} from "@solana/web3.js"; +import { createCreateMetadataAccountV3Instruction } from "@metaplex-foundation/mpl-token-metadata"; + +(async () => { + try { + const user = getKeypairFromEnvironment("SOLANA_SECRET_KEY"); + const connection = new Connection(clusterApiUrl("devnet")); + + console.log( + `🔑 We've loaded our keypair securely, using an env file! Our public key is: ${user.publicKey.toBase58()}` + ); + + const TOKEN_METADATA_PROGRAM_ID = new PublicKey( + "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s" //soldev metadata + ); + + // Substitute in your token mint account + const tokenMintAccount = new PublicKey( + "6vwCrpzcv5SRjZnJaJpezuLik8YuvuSWtJHbNqoBmPMp" //explorer token address + ); + + const metadataData = { + name: "UnclePhil Token", // Ensure this name is <= 32 characters + symbol: "PUN", + uri: "https://app.ardrive.io/#/file/ad53a03d-4b5a-466b-ad4f-88c09beecce6/view", + sellerFeeBasisPoints: 0, + creators: null, + collection: null, + uses: null, + }; + + const metadataPDAAndBump = PublicKey.findProgramAddressSync( + [ + Buffer.from("metadata"), + TOKEN_METADATA_PROGRAM_ID.toBuffer(), + tokenMintAccount.toBuffer(), + ], + TOKEN_METADATA_PROGRAM_ID + ); + + const metadataPDA = metadataPDAAndBump[0]; + + const transaction = new Transaction(); + + const createMetadataAccountInstruction = + createCreateMetadataAccountV3Instruction( + { + metadata: metadataPDA, + mint: tokenMintAccount, + mintAuthority: user.publicKey, + payer: user.publicKey, + updateAuthority: user.publicKey, + }, + { + createMetadataAccountArgsV3: { + collectionDetails: null, + data: metadataData, + isMutable: true, + }, + } + ); + + transaction.add(createMetadataAccountInstruction); + + const transactionSignature = await sendAndConfirmTransaction( + connection, + transaction, + [user] + ); + + const transactionLink = getExplorerLink( + "transaction", + transactionSignature, + "devnet" + ); + + console.log(`✅ Transaction confirmed, explorer link is: ${transactionLink}!`); + + const tokenMintLink = getExplorerLink( + "address", + tokenMintAccount.toString(), + "devnet" + ); + + console.log(`✅ Look at the token mint again: ${tokenMintLink}!`); + } catch (error) { + console.error(`Failed to create token metadata: ${error.message}`); + } +})(); diff --git a/UnclePhil-SPL/mint.ts b/UnclePhil-SPL/mint.ts new file mode 100644 index 0000000..35b14d6 --- /dev/null +++ b/UnclePhil-SPL/mint.ts @@ -0,0 +1,47 @@ +import { mintTo, getOrCreateAssociatedTokenAccount } from "@solana/spl-token"; +import { getKeypairFromEnvironment, getExplorerLink } from "@solana-developers/helpers"; +import "dotenv/config"; +import { Connection, PublicKey, clusterApiUrl } from "@solana/web3.js"; + +(async () => { + try { + const connection = new Connection(clusterApiUrl("devnet")); + const user = getKeypairFromEnvironment("SOLANA_SECRET_KEY"); + + console.log(`🔑 Loaded user keypair with public key: ${user.publicKey.toBase58()}`); + + const UNIT = Math.pow(10, 2); + const tokenMintAccount = new PublicKey("6vwCrpzcv5SRjZnJaJpezuLik8YuvuSWtJHbNqoBmPMp"); //explorer solana token address + const recipient = new PublicKey("47AzsyvjaPrd5eTwqveP4NSf1Fkq4ACbDfaAo6Kof36J"); // generated address + + // Ensure the recipient has an associated token account + const recipientTokenAccount = await getOrCreateAssociatedTokenAccount( + connection, + user, + tokenMintAccount, + recipient + ); + + console.log(`Recipient's associated token account: ${recipientTokenAccount.address.toBase58()}`); + + // Mint tokens to the recipient's associated token account + const transactionSignature = await mintTo( + connection, + user, + tokenMintAccount, + recipientTokenAccount.address, + user, + 100 * UNIT + ); + + const link = getExplorerLink( + "transaction", + transactionSignature, + "devnet" + ); + + console.log(`✅ Successfully minted tokens. Transaction: ${link}`); + } catch (error) { + console.error(`Failed to mint tokens: ${error.message}`); + } +})(); diff --git a/UnclePhil-SPL/tokenAccount.ts b/UnclePhil-SPL/tokenAccount.ts new file mode 100644 index 0000000..6ac8a3c --- /dev/null +++ b/UnclePhil-SPL/tokenAccount.ts @@ -0,0 +1,50 @@ +import { getOrCreateAssociatedTokenAccount } from "@solana/spl-token"; +import { + getKeypairFromEnvironment, + getExplorerLink, +} from "@solana-developers/helpers"; +import "dotenv/config"; +import { Connection, PublicKey, clusterApiUrl } from "@solana/web3.js"; + +const connection = new Connection(clusterApiUrl("devnet")); +const user = getKeypairFromEnvironment("SOLANA_SECRET_KEY"); + +console.log( + `Connection estabished and Public key: ${user.publicKey.toBase58()}` +); + +// CREATING A CONSTANT VERIABLE FOR ACCOUNT ADDRESSES +const Token_Mint_Account = "6vwCrpzcv5SRjZnJaJpezuLik8YuvuSWtJHbNqoBmPMp"; //explorer token address +const Recipient_Account = "xrwPFQEZCqFwLjtQC8Xg2FPPaoAh6enjE8ZG6Gj7gr5"; //solana phantom address + +// UPDATING THE DECLEARED ADDRESSES INTO THE NEW PUBLICkEY VIRIABLES +const tokenMintAccount = new PublicKey(Token_Mint_Account); +const recipientAccount = new PublicKey(Recipient_Account); + +// CREATING A TOKEN ACCOUNT +async function createTokenAccoount() { + try { + // CREATING A NEW TOKEN ACCOUNT + const tokenAccount = await getOrCreateAssociatedTokenAccount( + connection, + user, + tokenMintAccount, + recipientAccount + ); + + console.log("New Token Account", tokenAccount.address.toBase58()); + + // EXPLORER LINK TO VIEW THE TOKEN ACCOUNT + const ExplorerLink = getExplorerLink( + "address", + tokenAccount.address.toBase58(), + "devnet" + ); + + console.log(`Created token account: ${ExplorerLink}`); + } catch (error) { + console.log("Error creating a token account", error); + } +}; + +createTokenAccoount(); diff --git a/UnclePhil-SPL/tokenMint.ts b/UnclePhil-SPL/tokenMint.ts new file mode 100644 index 0000000..bffa433 --- /dev/null +++ b/UnclePhil-SPL/tokenMint.ts @@ -0,0 +1,40 @@ +import { + getExplorerLink, + getKeypairFromEnvironment, +} from "@solana-developers/helpers"; +import { createMint } from "@solana/spl-token"; +import { Connection, clusterApiUrl } from "@solana/web3.js"; + +import "dotenv/config"; + +(async () => { + // Defining the publickKey and Secret key of a User + const user = getKeypairFromEnvironment("SOLANA_SECRET_KEY"); + const connection = new Connection(clusterApiUrl("devnet")); + + console.log( + `Connection established, here is the public key:`, + user.publicKey.toBase58() + ); + + try { + // CREATING A NEW TOKEN MINT FOR THE SPL. + const tokenMint = await createMint( + connection, + user, + user.publicKey, + user.publicKey, + 2 + ); + + // Creating the publicAddressKey + const publicAddressLink = getExplorerLink( + "address", + tokenMint.toBase58(), + "devnet" + ); + console.log(`Token Mint created successfully:`, publicAddressLink); + } catch (error) { + console.error(`Failed to create token mint:`, error.message); + } +})(); diff --git a/UnclePhil-SPL/tokenTransfer.ts b/UnclePhil-SPL/tokenTransfer.ts new file mode 100644 index 0000000..e11e425 --- /dev/null +++ b/UnclePhil-SPL/tokenTransfer.ts @@ -0,0 +1,53 @@ +import { getOrCreateAssociatedTokenAccount, transfer } from "@solana/spl-token"; +import { + getKeypairFromEnvironment, + getExplorerLink, +} from "@solana-developers/helpers"; +import "dotenv/config"; +import { Connection, PublicKey, clusterApiUrl } from "@solana/web3.js"; + +const sender = getKeypairFromEnvironment("SOLANA_SECRET_KEY"); +const connection = new Connection(clusterApiUrl("devnet")); + +const recipient = new PublicKey("xrwPFQEZCqFwLjtQC8Xg2FPPaoAh6enjE8ZG6Gj7gr5"); +const tokenMintAccount = new PublicKey( + "6vwCrpzcv5SRjZnJaJpezuLik8YuvuSWtJHbNqoBmPMp" +); +const UNIT = Math.pow(10, 2); + +console.log(`Attempting to send 10 SUD token to ${recipient.toBase58()}...`); + +async function tokenTransfer() { + try { + const sourcedTokenAccount = await getOrCreateAssociatedTokenAccount( + connection, + sender, + tokenMintAccount, + sender.publicKey + ); + + const destinationTokenAccount = await getOrCreateAssociatedTokenAccount( + connection, + sender, + tokenMintAccount, + recipient + ); + + const transactionSignature = await transfer( + connection, + sender, + sourcedTokenAccount.address, + destinationTokenAccount.address, + sender, + 10 * UNIT + ); + + const link = getExplorerLink("transaction", transactionSignature, "devnet"); + + console.log(`Successfully sent 10 SUD to this address: ${link}`); + } catch (error) { + console.error("Error during token transfer:", error); + } +} + +tokenTransfer(); diff --git a/package-lock.json b/package-lock.json index 4f4f963..30dff67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2948,12 +2948,6 @@ "resolved": "https://registry.npmjs.org/fast-stable-stringify/-/fast-stable-stringify-1.0.0.tgz", "integrity": "sha512-wpYMUmFu5f00Sm0cj2pfivpmawLZ0NKdviQ4w9zJeR8JVtOpOxHmLaJuj0vxvGqMJQWyP/COUkF75/57OKyRag==" }, - "node_modules/fastestsmallesttextencoderdecoder": { - "version": "1.0.22", - "resolved": "https://registry.npmjs.org/fastestsmallesttextencoderdecoder/-/fastestsmallesttextencoderdecoder-1.0.22.tgz", - "integrity": "sha512-Pb8d48e+oIuY4MaM64Cd7OW1gt4nxCHs7/ddPPZ/Ic3sg8yVGM7O9wDvZ7us6ScaUupzM+pfBolwtYhN1IxBIw==", - "peer": true - }, "node_modules/figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", diff --git a/package.json b/package.json index 3615116..5a74167 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "typescript": "^4.6.4" }, "dependencies": { - "@metaplex-foundation/mpl-token-metadata": "^2.13.0", "@metaplex-foundation/js": "^0.17.12", + "@metaplex-foundation/mpl-token-metadata": "^2.13.0", "@solana-developers/helpers": "^2.3.0", "@solana/spl-token": "^0.4.6", "@solana/web3.js": "^1.91.8", From d074e977c98f085d00cd4e0850299b933b436988 Mon Sep 17 00:00:00 2001 From: Unclephil Date: Thu, 23 May 2024 21:18:29 +0100 Subject: [PATCH 3/4] day4: create to with token program --- UnclePhil-SPL/{tokenTransfer.ts => transferToken.ts} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename UnclePhil-SPL/{tokenTransfer.ts => transferToken.ts} (96%) diff --git a/UnclePhil-SPL/tokenTransfer.ts b/UnclePhil-SPL/transferToken.ts similarity index 96% rename from UnclePhil-SPL/tokenTransfer.ts rename to UnclePhil-SPL/transferToken.ts index e11e425..998a5aa 100644 --- a/UnclePhil-SPL/tokenTransfer.ts +++ b/UnclePhil-SPL/transferToken.ts @@ -17,7 +17,7 @@ const UNIT = Math.pow(10, 2); console.log(`Attempting to send 10 SUD token to ${recipient.toBase58()}...`); -async function tokenTransfer() { +async function transferToken() { try { const sourcedTokenAccount = await getOrCreateAssociatedTokenAccount( connection, @@ -50,4 +50,4 @@ async function tokenTransfer() { } } -tokenTransfer(); +transferToken(); From bd284c28d8c77d9b7e841e9a5b5de65e70f4f912 Mon Sep 17 00:00:00 2001 From: Unclephil Date: Thu, 23 May 2024 21:35:08 +0100 Subject: [PATCH 4/4] day 4 task --- UnclePhil-SPL/transferToken.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnclePhil-SPL/transferToken.ts b/UnclePhil-SPL/transferToken.ts index 998a5aa..4d60c0e 100644 --- a/UnclePhil-SPL/transferToken.ts +++ b/UnclePhil-SPL/transferToken.ts @@ -15,7 +15,7 @@ const tokenMintAccount = new PublicKey( ); const UNIT = Math.pow(10, 2); -console.log(`Attempting to send 10 SUD token to ${recipient.toBase58()}...`); +console.log(`Attempting to send 10 SUD token to :${recipient.toBase58()}...`); async function transferToken() { try {