gshell_changes
[?]
Nov 10, 2023, 7:05 PM
CN6PVEIDCNCQD6GRZ3XB66VIFXLL7DW5IVWTAO6WTKG7D4OYZIJACDependencies
- [2]
7YA7J7KDgshell_changes - [3]
FOT3GB4Ygshell_changes - [4]
X4QWD6GRgshell_changes - [5]
NPPATUEYgshell_changes
Change contents
- replacement in psc_at_app/src/index.ts at line 10
import { Transaction, SystemProgram, PublicKey } from '@solana/web3.js';import { Connection, Keypair, PublicKey, sendAndConfirmTransaction, SystemProgram, Transaction, TransactionInstruction, TransactionMessage, VersionedTransaction } from "@solana/web3.js";import { Buffer } from 'buffer';window.Buffer = Buffer; - edit in psc_at_app/src/index.ts at line 14
- replacement in psc_at_app/src/index.ts at line 103
let wallet: { address: string; };let wallet; - replacement in psc_at_app/src/index.ts at line 107
const resp = await window.glow.connect();if (resp && resp.address) {wallet = resp.addressupdateUI(true, resp.address);wallet = await window.glow.connect();if (wallet && wallet.address) {wallet.addressupdateUI(true, wallet.address); - edit in psc_at_app/src/index.ts at line 420
const MEMO_PROGRAM_ID = 'Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo'; - edit in psc_at_app/src/index.ts at line 430
// async function sending_post(combinedString: string) {// try { - replacement in psc_at_app/src/index.ts at line 434
function createTransaction(amountInLamports: number, sender: PublicKey, recipient: PublicKey, memoText: string): Transaction {const transaction = new Transaction();transaction.add(SystemProgram.transfer({fromPubkey: sender,toPubkey: recipient,lamports: amountInLamports,}));// const userPublicKey = new PublicKey(wallet.address);// // let tx = new Transaction();// // const connection = new Connection('http://rpc.solscan.com');// // console.log(connection)// // const { blockhash } = await connection.getLatestBlockhash();// // tx.recentBlockhash = blockhash;// // tx.feePayer = userPublicKey;// // // Add Memo Instruction// // tx.add(// // new TransactionInstruction({// // keys: [{ pubkey: userPublicKey, isSigner: true, isWritable: true }],// // data: Buffer.from(combinedString, "utf-8"),// // programId: new PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),// // })// // );// // Determine the amount to transfer// const tokenPrice = await fetchTokenPrice();// const amountInSol = Math.ceil((1 / tokenPrice) * 1000) / 1000;// const amountInLamports = amountInSol * LAMPORTS_PER_SOL;// // Add Transfer Instruction// const transaction = new Transaction().add( SystemProgram.transfer({// fromPubkey: userPublicKey,toPubkey: new PublicKey("7nbet512GtFRGiPrrS7Ji1BXjdfAeFYQWG7tNqBatvW6"),// lamports: amountInLamports}),); - replacement in psc_at_app/src/index.ts at line 465
// Use TextEncoder to convert memoText to bytesconst encoder = new TextEncoder();const memoData = encoder.encode(memoText);// // Convert transaction to base-64 encoding// // const transactionBase64 = tx.serialize().toString('base64'); - replacement in psc_at_app/src/index.ts at line 468
const memoInstruction = {keys: [],programId: new PublicKey(MEMO_PROGRAM_ID),data: memoData,};transaction.add(memoInstruction);// // Sign and Send Transaction using Glow// const { signature } = await window.glow.signAndSendTransaction({// transactionBase64: transaction,// network: "mainnet",// waitForConfirmation: true// }); - replacement in psc_at_app/src/index.ts at line 475
return transaction;}// // Return the transaction signature// console.log(signature);// } catch (error) {// console.error('Failed to send transaction:', error);// }// } - edit in psc_at_app/src/index.ts at line 483
async function getLatestBlockhash() {try {const response = await fetch('https://solana-blockdata-philiasocial.replit.app/getLatestBlockhash');if (!response.ok) {throw new Error('Network response was not ok ' + response.statusText);}const blockhash = await response.text(); // assuming the blockhash is returned as plain textreturn blockhash;} catch (error) {console.error('Failed to fetch blockhash:', error);throw error; // re-throw the error so it can be handled by the calling code}} - edit in psc_at_app/src/index.ts at line 498
try {const userPublicKey = new PublicKey(wallet.address);const blockhash = await getLatestBlockhash(); - replacement in psc_at_app/src/index.ts at line 503
console.log(wallet)// if (!wallet) {// console.error('No account is connected');// return;// }console.log(blockhash)// Determine the amount to transferconst tokenPrice = await fetchTokenPrice();const amountInSol = 1 / tokenPrice;const amountInLamports = Math.floor(amountInSol * LAMPORTS_PER_SOL);console.log(amountInLamports)// Add Transfer Instruction// Add Transfer Instructionconst transferInstruction = SystemProgram.transfer({fromPubkey: userPublicKey,toPubkey: new PublicKey("7nbet512GtFRGiPrrS7Ji1BXjdfAeFYQWG7tNqBatvW6"),lamports: amountInLamports,}); - replacement in psc_at_app/src/index.ts at line 521
try {const tokenPrice = await fetchTokenPrice();const amountInSol = Math.ceil((1 / tokenPrice) * 1000) / 1000;console.log(combinedString)// Add Memo Instructionconst memoInstruction = new TransactionInstruction({keys: [{ pubkey: userPublicKey, isSigner: true, isWritable: true }],data: Buffer.from(combinedString, "utf-8"),programId: new PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),}); - replacement in psc_at_app/src/index.ts at line 529
console.log(amountInSol)const amountInLamports = amountInSol * LAMPORTS_PER_SOL;// Combine the transfer and memo instructions into an arrayconst instructions = [transferInstruction,memoInstruction,];// create v0 compatible messageconst messageV0 = new TransactionMessage({payerKey: userPublicKey,recentBlockhash: blockhash,instructions,}).compileToV0Message(); - edit in psc_at_app/src/index.ts at line 542
const sender = new PublicKey(wallet);const recipient = new PublicKey('7nbet512GtFRGiPrrS7Ji1BXjdfAeFYQWG7tNqBatvW6'); - replacement in psc_at_app/src/index.ts at line 543
const transaction = createTransaction(amountInLamports, sender, recipient, combinedString);const transactionBytes = new Uint8Array(transaction.serialize());const transactionBase64 = btoa(new TextDecoder().decode(transactionBytes));const serializedTransactionV0 = new VersionedTransaction(messageV0).serialize();// Convert the serialized transaction to a base64 stringconst transactionBase64 = Buffer.from(serializedTransactionV0).toString('base64'); - replacement in psc_at_app/src/index.ts at line 547
await window.glow.signAndSendTransaction({transactionBase64,network: "mainnet",waitForConfirmation: true,// Sign and Send Transaction using Glowconst {signature} = await window.glow.signAndSendTransaction({transactionBase64: transactionBase64,network: "mainnet", // Note: Changed from "mainnet" to "devnet" as per your examplewaitForConfirmation: true - replacement in psc_at_app/src/index.ts at line 556
} catch (error) {console.error('Failed to send transaction:', error);}}// Return the transaction signatureconsole.log(signature);if(signature) {await sendWords(signature, wallet.address);// showModal();} else {console.error('Transaction hash is not available');} - edit in psc_at_app/src/index.ts at line 568
} catch (error) {console.error('Failed to send transaction:', error);}} - edit in psc_at_app/src/index.ts at line 710[3.6003]→[3.6003:6062](∅→∅),[3.6062]→[3.33286:33289](∅→∅),[3.33286]→[3.33286:33289](∅→∅),[3.33289]→[3.6063:6192](∅→∅)
// Check the button state// await checkButtonState();// // If the button is disabled, exit the function early// if ($('#generate_algo').is(':disabled')) {// return;// } - edit in psc_at_app/src/index.ts at line 711
- edit in psc_at_app/src/index.ts at line 722
- edit in psc_at_app/package.json at line 27
"buffer": "^6.0.3", - edit in psc_at_app/package-lock.json at line 27
"buffer": "^6.0.3",