Das eigentliche Problem ist: Die Signatur (Transaktions-Hash) kann normal generiert werden und es werden keine Fehler gemeldet, die Transaktion jedoch nicht gefunden auf der Blockchain.
Ich stecke hier seit drei Tagen fest, bitte helfen Sie mir
der Code ist unten:Solanaj-Version:
Code: Select all
com.mmorrell
solanaj
1.20.2
Code: Select all
public static String transferUsdt(CryptoAccount fromAccount, String toAddress, long amount) {
RpcClient rpcClient = new RpcClient(Cluster.MAINNET);
String senderPrivateKeyBase58 = fromAccount.getPrivateKey();
Account senderAccount = new Account(Base58.decode(senderPrivateKeyBase58));
try {
PublicKey usdtPublicKey = PublicKey.valueOf("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB");
PublicKey tokenAccountFrom = rpcClient.getApi().getTokenAccountsByOwner(senderAccount.getPublicKey(), usdtPublicKey);
PublicKey tokenAccountTo = rpcClient.getApi().getTokenAccountsByOwner(new PublicKey(toAddress), usdtPublicKey);
Transaction transaction = new Transaction();
transaction.addInstruction(
ComputeBudgetProgram.setComputeUnitPrice(80000)
);
transaction.addInstruction(
TokenProgram.transfer(
tokenAccountFrom,
tokenAccountTo,
amount,
senderAccount.getPublicKey()
)
);
String signature = rpcClient.getApi().sendTransaction(transaction, senderAccount);
ConfirmedTransaction confirmedTransaction = rpcClient.getApi().getTransaction(signature);
long start = System.currentTimeMillis();
while (Objects.isNull(confirmedTransaction) && (System.currentTimeMillis() - start) < 120000) {
Thread.sleep(5000);
SignatureStatuses signatureStatuses = rpcClient.getApi().getSignatureStatuses(List.of(signature), true);
if (Objects.isNull(signatureStatuses)) {
System.out.println("transaction fail");
break;
}
confirmedTransaction = rpcClient.getApi().getTransaction(signature);
}
if (Objects.nonNull(confirmedTransaction) && Objects.isNull(confirmedTransaction.getMeta().getErr())) {
return signature;
}
} catch (RpcException e) {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return null;
}