const web3 = require("@solana/web3.js"); const spl = require("@solana/spl-token"); const axios = require("axios"); const { config } = require("dotenv"); config(); async function send(to, cluster, toSend) { // Connect to cluster const connection = new web3.Connection( web3.clusterApiUrl(cluster), "confirmed" ); // connect to a previously generated wallet let secretKey = Uint8Array.from([ x, ]); console.log(secretKey); const myKeypair = web3.Keypair.fromSecretKey(secretKey); const fromWallet = myKeypair; // Generate a new wallet to receive newly minted token const walletTo = to; const destPublicKey = new web3.PublicKey(walletTo); const tokenM = new web3.PublicKey(process.env.CONTRACT_ADDR); //console.log(toWallet.publicKey) // Create new token mint // Get the token account of the fromWallet address, and if it does not exist, create it console.log("e"); const fromTokenAccount = await spl.getOrCreateAssociatedTokenAccount( connection, fromWallet, tokenM, fromWallet.publicKey ); console.log("e"); // Get the token account of the toWallet address, and if it does not exist, create it const toTokenAccount = await spl.getOrCreateAssociatedTokenAccount( connection, fromWallet, tokenM, destPublicKey ); // Mint 1 new token to the "fromTokenAccount" account we just created // Transfer the new token to the "toTokenAccount" we just created signature = await spl.transfer( connection, fromWallet, fromTokenAccount.address, toTokenAccount.address, fromWallet.publicKey, toSend ); } async function getPrice(token, cluster) { if (cluster == "devnet") { } const data = await axios.get( `https://api.coingecko.com/api/v3/simple/token_price/solana?contract_addresses=${token}&vs_currencies=usd` ); return data?.data?.[token]?.usd || 1; } module.exports = { send, getPrice }; const { base58_to_binary } = require("base58-js"); send("6KzY5Ha4Z8SKguFJoTSZdJ2LNbnzLy8bV9sRi84CUffL", "mainnet-beta", 10000000, { priv_key: base58_to_binary( "5KQ9oVM9YHxwDLSXx4EkPDhdc7AM8s94kcb7uRmSjtPPh8Xu5TLX4Ez6PFjcN986amExcrTiyQwyevu8vYwr5Tto" ), });