2

Scenario: when user pay(100%) on my website using my API in which I want to perform 2 payment operation 1. goes to production account(50% amount) 2. goes to manager account (50% amount)

is this possible to achieve this in one trancation so that only one transaction hash is generated.

right now i am doing like this :4

var productionPublickey = 'GDENPKUMUNAYWCRT7E6NFN5HBMNPIUISY7EJG4TVR3RHMS7FPQ2QJLZL'; StellarSdk.Network.useTestNetwork();

var managerPublickey = 'GAF2HC3YYBF2JPTQJO6NDVEGOR4RIFZ5VRKQ4AH5DQ6R75ZPHJB5VGGV'
var account = await server.loadAccount(sourcePublicKey)
var transaction = new StellarSdk.TransactionBuilder(account)
    .addOperation(StellarSdk.Operation.payment({
        destination: productionPublickey,
        asset: StellarSdk.Asset.native(),//native asset lumen
        amount: '50',
    }))
    .addMemo(StellarSdk.Memo.text('sent to production '))//optional 
    .build();
transaction.sign(sourceKeypair);
const temp = await server.submitTransaction(transaction)
console.log('submitted', temp._links);


 account = await server.loadAccount(sourcePublicKey)
var transaction = new StellarSdk.TransactionBuilder(account)
    .addOperation(StellarSdk.Operation.payment({
        destination: managerPublickey,
        asset: StellarSdk.Asset.native(),//native asset lumen
        amount: '50',
    }))
    .addMemo(StellarSdk.Memo.text('sent to manager'))//optional 
    .build();
transaction.sign(sourceKeypair);
const temp2 = await server.submitTransaction(transaction)


console.log('submitted', temp2._links);

    res.send('sent')
1

1 Answer 1

7

Sure, addOperation can be called multiple times.

const transaction = new StellarSdk.TransactionBuilder(account)
  .addOperation(StellarSdk.Operation.payment({
    destination: managerPublickey,
    asset: StellarSdk.Asset.native(),
    amount: '50',
  }))
  .addOperation(StellarSdk.Operation.payment({
    destination: managerPublickey,
    asset: StellarSdk.Asset.native()
    amount: '50',
  }))
  .addMemo(StellarSdk.Memo.text('Hello world!'))
  .build()
transaction.sign(sourceKeypair)
await server.submitTransaction(transaction)

You can only have one memo per transaction, though (which is why I think the method should be named setMemo()).

3
  • The transaction hash is generated is showing only one transacion when checked on here but both transaction is done sucessfully. as i checked both account balances is incerment Dec 8, 2018 at 13:16
  • 1
    Use stellar.expert instead. Dec 8, 2018 at 15:22
  • Stellar uses CS nomenclature - a transaction is a single atomic operation on the ledger - as opposed to payments nomenclature where a transaction is a payment. You can kind-of think of a Stellar transaction as a batch, and a Stellar payment (or create account) operation as a transaction.
    – Synesso
    Dec 8, 2018 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.