Created
May 4, 2022 08:27
-
-
Save wiyarmir/6a1b53113ea3676a6cdcd0582651f68f to your computer and use it in GitHub Desktop.
errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const newKeypair = Keypair.fromSeed(seed) | |
const associatedSource = await getAssociatedTokenAddress(usdcPublicKey, walletPublicKey) | |
const associatedNew = await getAssociatedTokenAddress(usdcPublicKey, newKeypair.publicKey) | |
const mint = await getMint(connection, usdcPublicKey) | |
const receiverAccount = await connection.getAccountInfo(associatedNew) | |
const instructions: TransactionInstruction[] = [] | |
instructions.push(createAssociatedTokenAccountInstruction(walletPublicKey, associatedNew, walletPublicKey, usdcPublicKey)) | |
const lamports = await getMinimumBalanceForRentExemptAccount(connection) | |
instructions.push( | |
SystemProgram.createAccount({ | |
fromPubkey: walletPublicKey, | |
newAccountPubkey: associatedNew, | |
space: ACCOUNT_SIZE, | |
lamports, | |
programId: TOKEN_PROGRAM_ID, | |
}), | |
createInitializeAccountInstruction(associatedNew, mint.mintAuthority, newKeypair.publicKey), | |
) | |
// TODO properly source | |
const DECIMALS_IN_USDC = 1000000 | |
const usdcAmount = Math.trunc(amount * DECIMALS_IN_USDC) | |
instructions.push(createTransferInstruction(associatedSource, associatedNew, walletPublicKey, usdcAmount)) | |
const transaction = new Transaction({ | |
feePayer: walletPublicKey, | |
recentBlockhash: (await connection.getLatestBlockhash()).blockhash, | |
}).add(...instructions) | |
const signed = await signTransaction(transaction) | |
const rawTransaction = signed.serialize({ requireAllSignatures: false }) | |
const transactionId = await connection.sendRawTransaction(transaction, { skipPreflight: true }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment