trustwallet / wallet-core

Cross-platform, cross-blockchain wallet library.
https://developer.trustwallet.com/wallet-core
Apache License 2.0
2.86k stars 1.6k forks source link

Transfer usdt on Sol #3801

Closed deeryoona closed 7 months ago

deeryoona commented 7 months ago

let tokenTransferMessage = SolanaTokenTransfer.with { $0.tokenMintAddress = "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB" $0.senderTokenAddress = "FWu8vwVdmVCb8mxx1pQmhwQXLoFgqDx8LTxsrR84mAvb" $0.recipientTokenAddress = "7i3F63k3jhdKSHC6obRrXkFCzmqnsad9V6QMvRiCcAxR" $0.amount = 1000000 $0.decimals = 6 } let privateKeyData = Data(hexString: priKey)!

    let input = SolanaSigningInput.with {
        $0.tokenTransferTransaction = tokenTransferMessage
        $0.recentBlockhash = recentBlockHash
        $0.privateKey = privateKeyData
    }

    let output: SolanaSigningOutput = AnySigner.sign(input: input, coin: .solana)
    print(output.encoded):

2R1XShikAW56x6AUMV56zrzrpyfpQ5mvX7GU4eqpqRcnUuRFQiAPRBj9B387Uxwza8Yt6TRC9oXhHh9nojrPyAX19BBxzGmt7PJR9NEqkYQZnPffLuL9sUnKhyCYxvkJp8xQPe8nB3ttnUd5H9SasniJmEaZH6crAsYG7oWkrH791YZGXZkiH6uuXnJmqxQgBV7a59FKgVmJcp3ytXBgwd7pdK1LyFkFjFnKA9kHwbH5Zdr65HAmHkLgskwwPdp26piZwpPYRQZ14n5txDxytnKhi7RvvXH8fzxa5zLiNfQyFDnqBtaEwmLfVY6HXKVcAArEQtpk44qjrCoY1

when i sendTransaction by sol rpc method,return: { error = { code = "-32002"; data = { accounts = ""; err = BlockhashNotFound; logs = ( ); returnData = ""; unitsConsumed = 0; }; message = "Transaction simulation failed: Blockhash not found"; }; id = 1; jsonrpc = "2.0"; }

recentBlockHash value i got it by sol rpc method "getRecentBlockhash"

i do not know how to solve this issue, and my english is poor,please help me

deeryoona commented 7 months ago

if i try it again,retun error: { code = "-32002"; data = { accounts = ""; err = { InstructionError = ( 0, InvalidAccountData ); }; innerInstructions = ""; logs = ( "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]", "Program log: Instruction: TransferChecked", "Program log: Error: InvalidAccountData", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1357 of 200000 compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction" ); returnData = ""; unitsConsumed = 1357; }; message = "Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction"; }

satoshiotomakan commented 7 months ago

Hi @deeryoona, This error means the SigningInput::recent_blockchash hasn't been mined yet, or not known by the Solana node you trying to broadcast the transaction to. Consider using https://www.quicknode.com/docs/solana/getRecentBlockhash "confirmation": "finalized" flag.

err = BlockhashNotFound;

As I can see, the recipient address does not exist 7i3F63k3jhdKSHC6obRrXkFCzmqnsad9V6QMvRiCcAxR, however you are only allowed to transfer SPL tokens to a Token address associated with a Solana account. Please consider using SolanaCreateAndTransferToken message instead.

"Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction";

deeryoona commented 7 months ago

Hi @deeryoona, This error means the SigningInput::recent_blockchash hasn't been mined yet, or not known by the Solana node you trying to broadcast the transaction to. Consider using https://www.quicknode.com/docs/solana/getRecentBlockhash "confirmation": "finalized" flag.

err = BlockhashNotFound;

As I can see, the recipient address does not exist 7i3F63k3jhdKSHC6obRrXkFCzmqnsad9V6QMvRiCcAxR, however you are only allowed to transfer SPL tokens to a Token address associated with a Solana account. Please consider using SolanaCreateAndTransferToken message instead.

"Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction";

example is : let createAndTransferTokenMessage = SolanaCreateAndTransferToken.with { $0.recipientMainAddress = "71e8mDsh3PR6gN64zL1HjwuxyKpgRXrPDUJT7XXojsVd" $0.tokenMintAddress = "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB" $0.recipientTokenAddress = "EF6L8yJT1SoRoDCkAZfSVmaweqMzfhxZiptKi7Tgj5XY" $0.senderTokenAddress = "ANVCrmRw7Ww7rTFfMbrjApSPXEEcZpBa6YEiBdf98pAf" $0.amount = 2900 $0.decimals = 6 } if accountA is sender,address is FWu8vwVdmVCb8mxx1pQmhwQXLoFgqDx8LTxsrR84mAvb accountB is receive address is 7i3F63k3jhdKSHC6obRrXkFCzmqnsad9V6QMvRiCcAxR tokenMintAddress is Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB

there are only 3 parameters,but example is need 4 parameters,I don't know how to set the corresponding parameters