1

let 4 accounts are there. The first one (customer) is creating trust with second account (distributor) which sending him 5 assets token. Now what i want is that the third account(having lots of same asset token) also transfer the same token(if he have that token in his account) to fourth account. These all above process should happen in same transaction and if anyone is failed, system automatically rollback. We can not share private key of one user to any other user.

3 operations need to compltet which is getting triggered on one event. Now we are trying to send token from multiple distributor to multiple account and those accounts have already trusted the distributor. Whether the below approach is correct or not? also i want to know that if any of the operation will fail then the entire transaction will fail? because my requirement is that all the transaction should get failed

   function finalSubmittion(){
   // Keys for accounts to issue and receive the new asset
   var admin = Stellar.Keypair

.fromSecret('SASIIJUEX7DRBTE6IXP3OPCYEXTTBUP6DEIUBWGGCPOKPIEJ35P4XK3T');

    var receivingKeyslockfirst = Stellar.Keypair

.fromSecret('SDQRQ2PVCHZZ2SI4XXWLVKEBUEZI3QABTYB2ZI2YUQ4T6HZLYLYAFOX4');

    var receivingKeyslocksecond = Stellar.Keypair

.fromSecret('SA7CUIF52CAPWQZISPKXMYSBHWPXXC55ZKOXFQCY7T6ZNFJQDSCVCQXK');

   var receivingKeyscurrentfirst = Stellar.Keypair

.fromSecret('SAA2ZPZNHJWA543NRTPUPYTGW7PL7EWNGNRQQ6HAFRY5QIVKFSJAQPSH');

           var receivingKeyscurrentsecond = Stellar.Keypair

.fromSecret('SA27KZR3DFTNAKBQPF3BX6NH5SSRX77CBNJKMUC4UWDXXXF7I5354CKM');

   var customer = Stellar.Keypair

.fromSecret('SCKMZXBEEPWTURZ3NMKQTLSOHSQSJZU4EGJRWSKLLS42VJSYWWIS2XJP');

   // Create an object to represent the new asset
   var fritokennew = new Stellar.Asset('FRICA', 'GDPSCSBLYQU4TXNPLTDFB2JUIZRQQ5CL2E2NYT5J76MUFEO2CP7S3MMF');



   server.loadAccount(admin.publicKey())
 .then(function(receiver) {
  var tx1 = new Stellar.TransactionBuilder(receiver, opts={fee:1})
// The `changeTrust` operation creates (or alters) a trustline
// The `limit` parameter below is optional
.addOperation(Stellar.Operation.payment({
  destination: customer.publicKey(),
  asset: fritokennew,
  amount: '10'
}))
// setTimeout is required for a transaction
.setTimeout(100)
.build();
 transaction.sign(customer);

 var tx2 = new Stellar.TransactionBuilder(receiver, opts={fee:1})
// The `changeTrust` operation creates (or alters) a trustline
// The `limit` parameter below is optional
.addOperation(Stellar.Operation.payment({
  destination: receivingKeyscurrentfirst.publicKey(),
  asset: fritokennew,
  amount: '10'
}))
// setTimeout is required for a transaction
.setTimeout(100)
.build();
 tx2.sign(receivingKeyslockfirst);

 var tx3 = new Stellar.TransactionBuilder(receiver, opts={fee:1})
// The `changeTrust` operation creates (or alters) a trustline
// The `limit` parameter below is optional
.addOperation(Stellar.Operation.payment({
  destination: receivingKeyscurrentsecond.publicKey(),
  asset: fritokennew,
  amount: '10'
}))
// setTimeout is required for a transaction
.setTimeout(100)
.build();
  tx3.sign(receivingKeyslocksecond);


  return server.submitTransaction(transaction);
 })

 }
2

You can put multiple operations for different accounts (identified by the 'source' parameter in each operation) into the same transaction. If one operation fails then all operations will fail. Instead of sharing secrets, share the transaction and let everyone append their signature. XDR representation is the way to share a transaction.

// tx object to xdr
let xdrString = tx.toEnvelope().toXDR('base64');

// somehow pass xdrString to next signer here

// xdr to tx object
let tx = new StellarSdk.Transaction(xdrString);
signer.sign(tx);

// repeat ...

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.