Sign Ripple transaction locally using ripple-lib-java

Since rippled 1.1.0 disables public signing by default, we either need to host our own API server or sign Ripple transaction locally. Fortunately, ripple-lib-java gives clue on how to do this in one of its example.

Long story short, we can use this simple method to do the signing:

import java.math.BigDecimal;
import com.ripple.core.types.known.tx.txns.Payment;
import com.ripple.core.types.known.tx.signed.SignedTransaction;
import com.ripple.core.coretypes.uint.UInt32;
import com.ripple.core.coretypes.AccountID;
import com.ripple.core.coretypes.Amount;


 * Generate signature locally for a payment transaction
 * @param xrpAmount
 * @param accountId
 * @param secret
 * @param addressTo
 * @param sequence
 * @param fee
 * @return transaction blob
public String sign(BigDecimal xrpAmount, String accountId, String secret, String addressTo, int sequence, int fee) {
  Payment payment = new Payment();, accountId);, addressTo);, new Amount(xrpAmount).toDropsString());, sequence);, String.valueOf(fee));
  SignedTransaction signed = payment.sign(secret);
  return signed.tx_blob;

The only catch is we need to provide sequence and fee ourselves. Luckily, we can use account_info API to get the sequence and use default transaction fee 10,000 drops (for testnet) or 10 drops (for main net).

Once we get the transaction blob, we just need to submit it using submit API. This snippet shows how to do it using a websocket client:

BigDecimal xrpAmount = new BigDecimal(1); // 1 XRP
String addressFrom = "...";
String addressFromSecret = "...";
String addressTo = "...";
// call account_info API and parse sequence from its response body
Integer sequence = client.getSequenceFromAccountInfoResponse(body);
int fee = 10000; // 10,000 drops
String txBlob = client.sign(

// send blob to submit API


0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments