Signing a Stellar transaction is identical to how we sign an Ethereum or Solana transaction with the exception that we need to pass in the Stellar specific RPC URL, chain ID, and method.
Before you submit a Stellar transaction, ensure that the Stellar account is funded and created on-chain. Failing to do so will result in an address not found error.
In the example we are going to update:
chainID to stellar:pubnet
rpcUrl to http://horizon.stellar.org
method to stellar_sendTransaction
params to a base64 encoded serialized Stellar transaction
Here is a short snippet of how to get the params using the stellar SDK. Note that in this example we assume the destination address is already created. For a complete example checkout this example repo:
constaxios=require('axios');constStellarSdk=require('stellar-sdk');var rpcUrl ='https://horizon-testnet.stellar.org';constserver=newStellarSdk.Horizon.Server(rpcUrl);constdestinationAddress="GDDRVYLDWMDZ2YEPDN6CIXD3ZJMCKTA4VEPZA2UYZBXSZDWIUMPGZE42"awaitserver.loadAccount(destinationAddress);constsourceAccount=awaitserver.loadAccount(stellarAddress);consttransaction=newStellarSdk.TransactionBuilder(sourceAccount, { fee:StellarSdk.BASE_FEE, networkPassphrase:StellarSdk.Networks.TESTNET,// Defaulting to testnet}).addOperation(StellarSdk.Operation.payment({ destination: destinationAddress,// example destination address asset:StellarSdk.Asset.native(),// Send XLM amount:'1',// amount to send }), ).setTimeout(30).build();// Serialize the transaction to XDRconstserializedTransaction=transaction.toXDR()// // Convert the serialized Buffer to a Base64 stringconstbase64Transaction=serializedTransaction.toString('base64');// // Sign the transactionconstsignResponse=awaitaxios.post(`${PORTAL_MPC_CLIENT_URL}/v1/sign`, { share:shares.ED25519.share, method:'stellar_sendTransaction', rpcUrl, params: base64Transaction, chainId:'stellar:testnet', }, { headers: { Authorization:`Bearer ${clientApiKey}` }, },);
Below is an example curl command for signing a Stellar message: