p2p-org/solana-swift

Transaction simulation failed

Closed this issue · 4 comments

So thats is my code (again)

       private func transferSolanaToken(mnemonic: [String], wallet: HDWallet) {
        try async {
            let endpoint = APIEndPoint(
                address: "https://api.mainnet-beta.solana.com",
                network: .mainnetBeta
            )
            do {
                let account = try await Account(phrase: mnemonic, network: .mainnetBeta, derivablePath: .default)
                let blockchainClient = BlockchainClient(apiClient: JSONRPCAPIClient(endpoint: endpoint))
                let preparedTransaction = try await blockchainClient.prepareSendingSPLTokens(
                    account: account,
                    mintAddress: "cxxShYRVcepDudXhe7U62QHvw8uBJoKFifmzggGKVC2",  // USDC mint
                    decimals: 6,
                    from: "DnTwkxa6xtFB72w2t9PPrwuxksAR1Gb663UWTGLbVpYM", // Your usdc address
                    to: "W3LJP23kwe4Vt6E2cpZ5DRHSNiJxfYwTxg8zuTmTKAT",
                    amount: UInt64(1)
                )
                
                print(preparedTransaction)
                
                let result = try await blockchainClient.sendTransaction(preparedTransaction: 
          preparedTransaction.preparedTransaction)
                
                print(result)
            }
            catch let error {
                print(error)
            }
        }
     }

And error say

    responseError(SolanaSwift.ResponseError(code: Optional(-32002), message: Optional("Transaction simulation failed: 
    it an account but found no record of a prior credit."), data: Optional(SolanaSwift.ResponseErrorData(logs: Optional([]), 
    numSlotsBehind: nil))))

What it's mean, and how make it work?
Can anyone help me?
Ty

On my account balance I see 1 CHICKS, and I am trying to send 0.005, and I still see Error, as I correctly understand you @bigearsenal from previous issue Please make sure that you account has enough 0.002044280 SOL (5000+2039280 lamports) for paying fee also, I have enough on my balance
Please provide more info how I can resolve it

Decimals for Solchick is 9. You have put wrong decimals

In from field, you have to put the correct SOLChick SPL token address, not the solana main account
G1uxCRh5dSmcZU7P5vnqerUp2TcAvBmTbDeqDwVULfcA

Because the decimals is equal to 9, you must put the amount = 0.5*10^9 = 500000000
If you want to send 0.5 CHICKS