Advertisement
obernardovieira

stella multi sig

Sep 6th, 2018
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.get('/multisig/:accf/:acct', (request, response) => {
  2.  
  3.     var pairSecond = StellarSdk.Keypair.fromSecret(request.params.accf);
  4.     var mainPair = StellarSdk.Keypair.fromSecret(request.params.acct);
  5.  
  6.     var pairToBePaid = StellarSdk.Keypair.fromSecret("SCK3Z2STK2BQ6WT3XDUJ4MM3TUO2NOWRYJBOAJTQHBPV5EGA7YKRGFHX");
  7.  
  8.     server.loadAccount(mainPair.publicKey()).then((account) => {
  9.  
  10.         var transaction = new StellarSdk.TransactionBuilder(account)
  11.             .addOperation(StellarSdk.Operation.payment({
  12.                 destination: pairToBePaid.publicKey(),
  13.                 asset: StellarSdk.Asset.native(),
  14.                 amount: "2" // 2000 XLM
  15.             }))
  16.             .addOperation(StellarSdk.Operation.setOptions({
  17.                 setFlags: 1,
  18.                 signer: {
  19.                     ed25519PublicKey: pairSecond.publicKey(),
  20.                     weight: 1
  21.                 },
  22.                 masterWeight: 1, // set master key weight
  23.                 lowThreshold: 1,
  24.                 medThreshold: 2, // a payment is medium threshold
  25.                 highThreshold: 2 // make sure to have enough weight to add up to the high threshold!
  26.             }))
  27.             .build();
  28.  
  29.         // now we need to sign the transaction with both the root and the secondaryAddress
  30.         transaction.sign(pairSecond);
  31.         transaction.sign(mainPair);
  32.  
  33.         server.submitTransaction(transaction)
  34.             .then(() => {
  35.                 response.send('2 lumens sent to ' + pairToBePaid.publicKey())
  36.             })
  37.             .catch((err) => {
  38.                 console.log(err.response.data.extras.result_codes);
  39.                 response.send('An error ocurred!')
  40.             });
  41.  
  42.     }).catch((err) => {
  43.         console.log(err.response.data.extras.result_codes);
  44.         response.send('An error ocurred!')
  45.     });
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement