send solana token with spl-token
Thu Jan 26 2023 19:10:38 GMT+0000 (Coordinated Universal Time)
Saved by
@luisjdominguezp
import { Keypair, PublicKey, Connection, clusterApiUrl, LAMPORTS_PER_SOL } from "@solana/web3.js";
import { getOrCreateAssociatedTokenAccount, transfer } from "@solana/spl-token";
(async() => {
const connection = new Connection(clusterApiUrl('devnet'), "confirmed");
let secretKey = Uint8Array.from([OBTENER de $HOME/.config/solana/id.son]);
const myKeypair = Keypair.fromSecretKey(secretKey);
const fromWallet = myKeypair;
console.log(fromWallet.publicKey)
console.log(fromWallet.secretKey)
const walletTo = "CLAVE PUBLICA DE WALLET RECEPTORA (CREAR OTRA)"
const destPublicKey = new PublicKey(walletTo)
const destMint: PublicKey = new PublicKey("TOKEN CREADO CON 1000000 de TOKENS")
const fromTokenAccount = await getOrCreateAssociatedTokenAccount(
connection,
fromWallet,
destMint,
fromWallet.publicKey
)
const toTokenAccount = await getOrCreateAssociatedTokenAccount(
connection,
fromWallet,
destMint,
destPublicKey
)
let signature = await transfer(
connection,
fromWallet,
fromTokenAccount.address,
toTokenAccount.address,
fromWallet.publicKey,
3*LAMPORTS_PER_SOL
)
console.log(signature)
})();
content_copyCOPY
Comments