How to use the stellar-sdk.Operation function in stellar-sdk

To help you get started, we’ve selected a few stellar-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikedeshazer / StellarXMarketMaker / lib / stellarSDKWrapper.js View on Github external
.then(async (account) => {
                let transaction = new StellarSdk.TransactionBuilder(account)
                    // Add a payment operation to the transaction
                    .addOperation(StellarSdk.Operation.createAccount({
                        destination: newPublicKey,
                        startingBalance: startingBalance, //At least 1 XLM to active new account
                    }))
                    // Uncomment to add a memo (https://www.stellar.org/developers/learn/concepts/transactions.html)
                    .addMemo(StellarSdk.Memo.text('Create a new account!'))
                    .build();

                // Sign this transaction with the secret key
                transaction.sign(srcKeyPair);

                // Let's see the XDR (encoded in base64) of the transaction we just built
                console.log(transaction.toEnvelope().toXDR('base64'));

                // Submit the transaction to the Horizon server. The Horizon server will then
                // submit the transaction into the network for us.
                return await server.submitTransaction(transaction)
github michielmulders / stellar-js-sdk / src / app.js View on Github external
const makePayment = async (req, res) => {
  const transaction = new Stellar.TransactionBuilder(accountA)
    .addOperation(Stellar.Operation.payment({
      destination: pairB.publicKey(),
      asset: Stellar.Asset.native(),
      amount: '30.0000001'
    }))
    .addOperation(Stellar.Operation.payment({
      destination: pairB.publicKey(),
      asset: Stellar.Asset.native(),
      amount: '2.0005682'
    }))
    .build()

  transaction.sign(pairA)

  // Let's see the XDR (encoded in base64) of the transaction we just built
  console.log("\nXDR format of transaction: ", transaction.toEnvelope().toXDR('base64'))

  try {
    const transactionResult = await server.submitTransaction(transaction)

    console.log('\n\nSuccess! View the transaction at: ')
    console.log(transactionResult._links.transaction.href)
github Block-Equity / desktop-wallet / app / services / networking / horizon.js View on Github external
.then(sourceAccount => {
      var transaction = new StellarSdk.TransactionBuilder(sourceAccount)
        .addOperation(StellarSdk.Operation.changeTrust(payload))
        .build()
        transaction.sign(sourceKeys)
        server.submitTransaction(transaction)
        .then( transactionResult => {
          resolve({
            payload: 'Success',
            error: false
          })
        })
        .catch( err => {
          console.log('An error has occured:')
          console.log(err)
          reject({error: true, errorMessage: err})
        })
    })
  })
github Block-Equity / desktop-wallet / app / services / networking / horizon.js View on Github external
.then(sourceAccount => {
      var transaction = new StellarSdk.TransactionBuilder(sourceAccount)
        .addOperation(StellarSdk.Operation.setOptions({ inflationDest: INFLATION_DESTINATION }))
        .build()
      transaction.sign(sourceKeys)

      server.submitTransaction(transaction)
      .then( transactionResult => {
        resolve({ payload: transactionResult, error: false })
      }).catch( err => {
        console.log(err)
        reject({ errorMessage: err, error: true })
      })
    })
  })
github ncent / ncent.github.io / MobileWallet / Actions / SignupActions.js View on Github external
.then(function(account) {
				  console.log("trusting the ncnt wallet");
				  var NCNT = new StellarSdk.Asset('NCNT', 'GBWOFUTXKI7IANMVHGBZX7KKK4LDDH7OVJ4C3WLX4V7M3WH2OKPBQEN5');
				  var transaction = new StellarSdk.TransactionBuilder(account)
				  .addOperation(StellarSdk.Operation.changeTrust({
				  	destination: 'GB4IIY4IWZHCNPLCOY7IPYSZF6VUWGAVZ75JAPZSSUMYXPQQL44AB5L5',
				  	asset: NCNT	
				  }))
				  .build();
				  console.log('************************************************************');
				  console.log(wallet.canSign());
				  transaction.sign(wallet);
				  console.log("submitting trust transaction");
				  return server.submitTransaction(transaction);
				})
				.then(response => {
github swaponline / swap.react / shared / redux / actions / xlm.js View on Github external
const runOperation = (from, type, options) => {
  const operationBuilder = sdk.Operation[type]

  if (!operationBuilder) {
    return Promise.reject(new Error(`Unknown operation type: ${type}`))
  }

  return xlm.server.loadAccount(from.publicKey())
    .then(sourceAccount => {
      const operation = operationBuilder.call(sdk.Operation, options)
      const tx = new sdk.TransactionBuilder(sourceAccount)
        .addOperation(operation)
        .build()

      tx.sign(from)
      return xlm.server.submitTransaction(tx)
    })
}
github pakokrew / stellar-portal / app / js / helpers / Stellar.js View on Github external
export const sendPayment = ({ asset, keypair, sourceAccount, destination, amount }) => {
  const sequenceNumber = sourceAccount.sequence;
  const sourceAddress = keypair.accountId();
  const transAccount = new Stellar.Account(sourceAddress, sequenceNumber);

  const transaction = new Stellar.TransactionBuilder(transAccount)
    .addOperation(Stellar.Operation.payment({
      destination: destination,
      asset: asset,
      amount: amount
    }))
    .build();

  transaction.sign(keypair);

  return getServerInstance()
    .submitTransaction(transaction);
};
github future-tense / stargazer / app / pages / add-account / create-personal.component.js View on Github external
.then(account => {
				const tx = new StellarSdk.TransactionBuilder(account)
				.addOperation(StellarSdk.Operation.createAccount({
					destination: publicKey,
					startingBalance: this.account.amount.toString()
				}))
				.setTimeout(0)
				.build();

				return {
					tx: tx,
					network: network
				};
			})
			.then(this.Reviewer.review)
github pakokrew / stellar-portal / app / js / helpers / Stellar.js View on Github external
export const changeTrust = ({ asset, limit, keypair, sourceAccount }) => {
  const sequenceNumber = sourceAccount.sequence;
  const sourceAddress = keypair.accountId();
  const transAccount = new Stellar.Account(sourceAddress, sequenceNumber);
  const trustLimit = isString(limit) ? limit : undefined;

  const transaction = new Stellar.TransactionBuilder(transAccount)
    .addOperation(Stellar.Operation.changeTrust({
      asset,
      limit: trustLimit,
    }))
    .build();

  transaction.sign(keypair);

  return getServerInstance()
    .submitTransaction(transaction);
};
github future-tense / stargazer / app / pages / account-settings / inflation-destination.component.js View on Github external
.then(account => {

			const tx = new StellarSdk.TransactionBuilder(account)
			.addOperation(StellarSdk.Operation.setOptions({
				inflationDest: destination
			}))
			.setTimeout(0)
			.build();

			return {
				tx: tx,
				network: this.account.network
			};
		})