Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.get('/multisig/:toaccount', (request, response) => {
- var pairSecond = StellarSdk.Keypair.random();
- server.loadAccount(pairMaster.publicKey()).then((account) => {
- var secondaryAddress = pairSecond.publicKey();
- var transaction = new StellarSdk.TransactionBuilder(account)
- .addOperation(StellarSdk.Operation.setOptions({
- signer: {
- ed25519PublicKey: secondaryAddress,
- weight: 1
- }
- }))
- .addOperation(StellarSdk.Operation.setOptions({
- masterWeight: 1, // set master key weight
- lowThreshold: 1,
- medThreshold: 2, // a payment is medium threshold
- highThreshold: 2 // make sure to have enough weight to add up to the high threshold!
- }))
- .build();
- transaction.sign(pairMaster); // only need to sign with the root signer as the 2nd signer won't be added to the account till after this transaction completes
- // now create a payment with the account that has two signers
- var transaction = new StellarSdk.TransactionBuilder(account)
- .addOperation(StellarSdk.Operation.payment({
- destination: StellarSdk.Keypair.fromSecret(request.params.toaccount).publicKey(),
- asset: StellarSdk.Asset.native(),
- amount: "2" // 2000 XLM
- }))
- .build();
- var secondKeypair = StellarSdk.Keypair.fromSecret(pairSecond.secret());
- // now we need to sign the transaction with both the root and the secondaryAddress
- transaction.sign(pairMaster);
- transaction.sign(secondKeypair);
- server.submitTransaction(transaction)
- .then(() => {
- response.send(request.params.amount + ' lumens sent to ' + pairTo.publicKey())
- })
- .catch((err) => {
- console.log(err.response.data.extras.result_codes);
- response.send('An error ocurred!')
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement