How to use the stellar-sdk.TransactionBuilder 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 irisli / bookmaker / deleteAllOffers.js View on Github external
module.exports = async function deleteAllOffers(Server, account, keypair) {
  // Get the offer IDs
  const offersForTarget = await Server.offers('accounts', keypair.accountId())
    .order('asc')
    .limit(20)
    .call();

  if (offersForTarget.records.length === 0) {
    return 0;
  }

  let transaction = new StellarSdk.TransactionBuilder(account);
  console.log(`Deleting ${offersForTarget.records.length} offers for ${keypair.accountId()}`);
  offersForTarget.records.forEach((record) => {
    const offerId = record.id;
    transaction = transaction.addOperation(StellarSdk.Operation.manageOffer({
      // It doesn't matter who the issuer is since this is just going to get deleted
      buying: StellarSdk.Asset.native(),
      selling: new StellarSdk.Asset('0000', account.accountId()),
      amount: '0',
      price: '1',
      offerId,
    }));
  });

  // transaction = transaction.addMemo(StellarSdk.Memo.text(`bookmaker ${version}`));
  transaction = transaction.build();
github DnD-industries / stellar_tipping_bot / src / stellar / index.js View on Github external
.then(async function(sourceAccount) {
            // Start building the transaction.
            console.log("Source account sequence:", sourceAccount.sequenceNumber());
            while (sourceAccount.sequenceNumber() <= lastSequenceNumber) {
              console.log("Sequence number " + sourceAccount.account + " l.t.e. to last sequence of " + lastSequenceNumber);
              sourceAccount.incrementSequenceNumber();
              console.log("New source account sequence:", sourceAccount.sequenceNumber());
            }
            lastSequenceNumber = sourceAccount.sequenceNumber();
            var transaction = new StellarSdk.TransactionBuilder(sourceAccount)
              .addOperation(StellarSdk.Operation.payment({
                destination: to,
                // Because Stellar allows transaction in many currencies, you must
                // specify the asset type. The special "native" asset represents Lumens.
                asset: StellarSdk.Asset.native(),
                amount: amount
              }))
              // A memo allows you to add your own metadata to a transaction. It's
              // optional and does not affect how Stellar treats the transaction.
              // We substring here to limit memo strings to the allowed 28-byte maximum.
              .addMemo(StellarSdk.Memo.text(memo.length ? memo.substring(0,27) : "XLM Tipping Bot"))
              .build();
            // Sign the transaction to prove you are actually the person sending it.
            transaction.sign(keyPair);

            resolve(transaction);
github irisli / bookmaker / simplePayment.js View on Github external
module.exports = async function simplePayment(Server, account, keypair, opts) {
  const operationOpts = {
    destination: opts.destination,
    asset: opts.asset,
    amount: opts.amount,
  };

  const transaction = new StellarSdk.TransactionBuilder(account)
    .addOperation(StellarSdk.Operation.payment(operationOpts))
    // .addMemo(StellarSdk.Memo.text(`bookmaker ${version}`))
    .build();
  transaction.sign(keypair);

  const transactionResult = await Server.submitTransaction(transaction);
  // console.log('\n');
  // console.log(operationOpts);
  // console.log('View the transaction at: https://www.stellar.org/laboratory/#xdr-viewer?type=TransactionEnvelope&network=public&input=' + encodeURIComponent(transactionResult.envelope_xdr));
  // console.log('\n');
};
github stellar-deprecated / stellar-sms-client / lib / commands / send-command.js View on Github external
.then(account => {
            console.log('Account loaded.');
            let asset = Asset.native();
            let amount = this._amount;
            let transaction = new TransactionBuilder(account)
              .addOperation(Operation.payment({
                destination: res.body.federation_json.destination_new_address,
                asset: asset,
                amount: amount
              }))
              .build();

            transaction.sign(keypair);

            stex.horizon.submitTransaction(transaction)
              .then(transactionResult => {
                console.log(transactionResult);
                stex.sms.sender.sendMessage(this._from, 'Transaction sent!');
              })
              .catch(e => {
                console.error(e);
github layr-team / Layr / utils / stellar.js View on Github external
}).then((sourceAccount) => {
      console.log("building transaction....")
      let transaction = new StellarSdk.TransactionBuilder(sourceAccount)
      .addOperation(StellarSdk.Operation.payment({
        destination: destinationAccountId,
        asset: StellarSdk.Asset.native(),
        amount: amount
      })).build();
      transaction.sign(sourceKeys);
      return stellarServer.submitTransaction(transaction);
    }).then((result) => {
      onSuccess(result)
github future-tense / stargazer / app / pages / account-settings / account-trustlines.component.js View on Github external
createTransaction(account) {

		const builder = new StellarSdk.TransactionBuilder(account)
		.setTimeout(0);

		function addOperation(trustline) {
			const object = trustline.object;
			const params = {
				asset: new StellarSdk.Asset(object.asset_code, object.asset_issuer)
			};

			if (trustline.state === false) {
				params.limit = '0';
			}

			builder.addOperation(StellarSdk.Operation.changeTrust(params));
		}

		this.anchors.forEach(anchor => {
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 mobius-network / wallet / src / state / sagas / hackathonVote / sendHackathonVoteSaga.js View on Github external
const { payload } = args;

    yield call(navigator.navigate, 'HackathonVote', 'Loading');

    const destination = HACKATHON_VOTING_ACCOUNT;

    const account = yield select(getMasterAccount);
    const keypair = yield select(getKeypairFor);

    const paymentOp = Operation.payment({
      destination,
      amount: '0.0000001',
      asset: assets.xlm,
    });

    let tx = new TransactionBuilder(account);

    const memoHash = createMemoHash(payload, keypair.publicKey());

    tx = tx.addMemo(Memo.hash(memoHash));
    tx = tx.addOperation(paymentOp).build();
    tx.sign(keypair);

    yield call(safeLoadAccount, destination);
    yield call(submitTransaction, tx);

    yield call(saveHackatonVote);

    yield call(navigator.navigate, 'HackathonVote', 'Notice', {
      action: ({ navigate }) => navigate('Dashboard'),
      type: 'success',
      message: i18n.t('hackathonVote.success'),
github jackyzha0 / PacketBook / functions / messaging / __main__.js View on Github external
.then(function(sourceAccount) {
		    transaction = new StellarSdk.TransactionBuilder(sourceAccount)
		      .addOperation(StellarSdk.Operation.payment({
		        destination: destinationId,
		        asset: StellarSdk.Asset.native(),
		        amount: amnt.toString()
		      }))
		      .addMemo(StellarSdk.Memo.text('Test Transaction'))
		      .build();
		    transaction.sign(sourceKeys);
		    return server.submitTransaction(transaction);
		  })
		  .then(function(result) {