Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions ReadData/writingSol.ts
Original file line number Diff line number Diff line change
@@ -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}!`);
33 changes: 33 additions & 0 deletions Reading/esrun-1716146495187.tmp.mjs
Original file line number Diff line number Diff line change
@@ -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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsicGhpbC50cyJdLAogICJzb3VyY2VSb290IjogIkM6XFxVc2Vyc1xccGhpbGlcXE9uZURyaXZlXFxEZXNrdG9wXFxQcm9qZWN0XFxGdWxsc3RhY2tcXDMwLURheXMtU29sYW5hLURldmVsb3Blci1Cb290Y2FtcFxcUmVhZGluZyIsCiAgInNvdXJjZXNDb250ZW50IjogWyJpbXBvcnQgeyBDb25uZWN0aW9uLCBQdWJsaWNLZXksIGNsdXN0ZXJBcGlVcmwsIExBTVBPUlRTX1BFUl9TT0wgfSBmcm9tIFwiQHNvbGFuYS93ZWIzLmpzXCI7XHJcblxyXG4oYXN5bmMgKCkgPT4ge1xyXG4gIGNvbnN0IGNvbm5lY3Rpb24gPSBuZXcgQ29ubmVjdGlvbihjbHVzdGVyQXBpVXJsKFwiZGV2bmV0XCIpKTtcclxuICBjb25zdCBhZGRyZXNzU3RyaW5nID0gJ3hyd1BGUUVaQ3FGd0xqdFFDOFhnMkZQUGFvQWg2ZW5qRThaRzZHajdncjUnO1xyXG4gIFxyXG4gIGxldCBhZGRyZXNzO1xyXG4gIHRyeSB7XHJcbiAgICBhZGRyZXNzID0gbmV3IFB1YmxpY0tleShhZGRyZXNzU3RyaW5nKTtcclxuICB9IGNhdGNoIChlKSB7XHJcbiAgICBjb25zb2xlLmVycm9yKGBJbnZhbGlkIHB1YmxpYyBrZXkgcHJvdmlkZWQ6ICR7YWRkcmVzc1N0cmluZ31gKTt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PQUFQO0FBQ0EsWUFBUSxNQUFNLDRCQUE0QixNQUFNLFNBQVM7QUFBQSxFQUMzRDtBQUNGLEdBQUc7IiwKICAibmFtZXMiOiBbXQp9Cg==


28 changes: 28 additions & 0 deletions Reading/phil.ts
Original file line number Diff line number Diff line change
@@ -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}`);
}
})();
2 changes: 1 addition & 1 deletion Token-Program/tokenMint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
2 changes: 1 addition & 1 deletion Token-Program/transferToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ async function transferToken() {
}
}

transferToken();
transferToken();
100 changes: 100 additions & 0 deletions UnclePhil-SPL/metadata.ts
Original file line number Diff line number Diff line change
@@ -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}`);
}
})();
47 changes: 47 additions & 0 deletions UnclePhil-SPL/mint.ts
Original file line number Diff line number Diff line change
@@ -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}`);
}
})();
50 changes: 50 additions & 0 deletions UnclePhil-SPL/tokenAccount.ts
Original file line number Diff line number Diff line change
@@ -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();
40 changes: 40 additions & 0 deletions UnclePhil-SPL/tokenMint.ts
Original file line number Diff line number Diff line change
@@ -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);
}
})();
Loading