solana-labs / solana-program-library

A collection of Solana programs maintained by Solana Labs
https://solanalabs.com
Apache License 2.0
3.5k stars 2.04k forks source link

Send USDC on Solana network #3267

Closed hungtnb closed 2 years ago

hungtnb commented 2 years ago

Hi there!

I got an issue when trying to send USDC on Solana network

Source code for create transaction: `async function transactionItem(fromKeyPair: solWeb3.Keypair, toAddress: string) { const toPubKey = new solWeb3.PublicKey(toAddress)

if (tokenInfo.symbol === SOL_SYMBOL) {
  // send SOLANA token
  return new solWeb3.Transaction().add(
    solWeb3.SystemProgram.transfer({
      fromPubkey: fromKeyPair.publicKey,
      toPubkey: new solWeb3.PublicKey(toPubKey),
      lamports: solWeb3.LAMPORTS_PER_SOL * +(amount || 0),
    })
  )
} else {
  // send other tokens Example: USDC
  const mint = new solWeb3.PublicKey(`${tokenInfo.address}`)

  const fromTokenAccount = await splToken.getOrCreateAssociatedTokenAccount(
    SOL_CONNECTION,
    fromKeyPair,
    mint,
    fromKeyPair.publicKey
  )

  const toTokenAccount = await splToken.getOrCreateAssociatedTokenAccount(
    SOL_CONNECTION,
    fromKeyPair,
    mint,
    new solWeb3.PublicKey(`${toAddress}`)
  );

  return new solWeb3.Transaction().add(
    splToken.createTransferInstruction(
      fromTokenAccount.address, // source address
      toTokenAccount.address, // dest address
      fromKeyPair.publicKey,
      Number(amount)*Math.pow(10, tokenInfo.decimals),
      [],
      undefined
    )
  )

}

}`

Response ERROR: [RangeError: Maximum call stack size exceeded.]

Evirontment: "react-native": "0.68.2", "@solana/spl-token": "0.2.0", "@solana/web3.js": "1.35.1",

In this case, it onlu able to send Solana but not for USDC. I try to upgrade solana/web3.js to 1.44.0 but still got same error.

I'm also try a lot of solution but nothing can help. Please help this case. Thanks a lot

joncinque commented 2 years ago

Hi there, we don't use GitHub for support! Instead we invite you to ask a question on StackOverflow with the "solana" tag or join us on Discord in #developer-support https://discord.gg/solana.

To quickly answer your question, there's probably an issue in the amount parameter, so it's creating something too big. More info at https://stackoverflow.com/questions/22123769/rangeerror-maximum-call-stack-size-exceeded-why