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')
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()).

  • 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 – Prashant Gangwar Dec 8 '18 at 13:16
  • 1
    Use stellar.expert instead. – Johan Stén Dec 8 '18 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 '18 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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