Problem summary:
Code written with one version of sdk doesn't work when sdk is updated and Our old software stopped working , I went in to find the problem. It was written in 2019 and our custom tokens just worked fine.
I see several code examples online, none worked for me.
Here is the new code , I tried sdk jar 0.20, 0.38 and 0.40 .
The transaction is always reported successful but balances in sender and receiver accounts are not updated .
Only on stellar.expert website I can verify that transaction went through from sender.
There are examples and document provided code online that doesn't work . I have tried it in several ways in last 3 days.
I tried sdk 0.36 jar also. The function parameters are different in all sdk version.
try {
// Create a ChangeTrustOperation to trust the custom token
Asset customToken = new AssetTypeCreditAlphaNum4("PYBC", COIN_ISSUER_PYBC);
ChangeTrustOperation changeTrustOperation = new ChangeTrustOperation.Builder(customToken, "1000").build();
// Build the transaction
Transaction transaction = new Transaction.Builder(sourceAccount, Network.PUBLIC)
.addOperation(changeTrustOperation)
.addMemo(Memo.text("trustline"))
.setTimeout(180) // Set a timeout in seconds
.setBaseFee(100)
.build();
// Sign the transaction
transaction.sign(source);
// Submit the transaction to the Stellar network
SubmitTransactionResponse response = server.submitTransaction(transaction);
if (response.isSuccess()) {
System.out.println("Trustline created successfully!");
} else {
System.out.println("Transaction failed with error: " + response.getResultXdr());
}
} catch (Exception e) {
e.printStackTrace();
}