Categories
Solana

Hey everyone,

I’m trying to send USDT using Node.js, but I’m running into an issue. Can anyone help me out?

async sendUSDT(

senderPrivateKeyHex: string,

recipientAddress: string,

amount: number,

) {

try {

const USDT_MINT_ADDRESS = new PublicKey(

'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',

); // Exemplo, use o endereço correto para USDT

const recipientPublicKey = new PublicKey(recipientAddress);

// Converter a chave privada Base58 para um Keypair

const privateKeyBytes = bs58.decode(senderPrivateKeyHex);

const keypair = Keypair.fromSecretKey(privateKeyBytes);

// Conectar-se Γ  rede Solana via Alchemy

const connection = new Connection(ALCHEMY_API_URL, 'confirmed');

let sourceAccount = await getOrCreateAssociatedTokenAccount(

connection,

keypair,

USDT_MINT_ADDRESS,

new PublicKey(process.env.WALLET_G2),

);

let destinationAccount = await getOrCreateAssociatedTokenAccount(

connection,

keypair,

USDT_MINT_ADDRESS,

new PublicKey(recipientAddress),

);

console.log('Decimals Number init');

const numberDecimals = await this.getTokenDecilmals(

'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',

);

console.log('Decimals Number finish');

console.log(numberDecimals);

console.log('init new Transaction');

const lastBlockHash = await connection.getLatestBlockhash('confirmed');

const transaction = new Transaction(lastBlockHash);

transaction.add(

createTransferInstruction(

sourceAccount.address,

destinationAccount.address,

keypair.publicKey,

amount * Math.pow(10, numberDecimals),

),

);

const assing = await sendAndConfirmTransaction(connection, transaction, [

keypair,

]);

console.log(assing);

return;

} catch (error) {

if (error instanceof SendTransactionError) {

console.error('Erro ao enviar USDT:', error);

const logs = error.logs;

console.error('Logs de erro:', logs);

} else {

console.error('Erro ao enviar USDT:', error);

}

}

}

submitted by /u/Artistic-Raccoon4711
[link] [comments]

Join The SmashBotAI Telegram Community Now! Get trade alerts, smashable token trade ideas, and more!

https://t.me/smashbotcommunity

Start Trading Now:

SmashBotAI Telegram Bot

Claim Your $SMASH Airdrop Now!

Leave a Reply

Your email address will not be published. Required fields are marked *

Join The SmashBotAI Telegram Community Now! Get trade alerts, smashable token trade ideas, and more! https://t.me/smashbotcommunity

Start Trading Now:
SmashBotAI Telegram Bot

Claim Your $SMASH Airdrop Now!

Categories