Class

Transaction

Transaction(envelope, networkPassphraseopt)

Use TransactionBuilder to build a transaction object. If you have an object or base64-encoded string of the transaction envelope XDR, use TransactionBuilder.fromXDR.

Once a Transaction has been created, its attributes and operations should not be changed. You should only add signatures (using Transaction#sign) to a Transaction object before submitting to the network or forwarding on to additional signers.

Constructor

# new Transaction(envelope, networkPassphraseopt)

Parameters:
Name Type Attributes Description
envelope string | xdr.TransactionEnvelope

transaction envelope object or base64 encoded string

networkPassphrase string <optional>

passphrase of the target stellar network (e.g. "Public Global Stellar Network ; September 2015")

View Source js-stellar-base/src/transaction.js, line 32

Extends

Classes

Transaction

Members

Array.<string>

# readonly extraSigners

array of extra signers (StrKeys)

View Source js-stellar-base/src/transaction.js, line 197

object

# readonly ledgerBounds

Properties:
Name Type Description
minLedger number

smallest ledger bound (uint32)

maxLedger number

largest ledger bound (or 0 for inf)

View Source js-stellar-base/src/transaction.js, line 149

string

# readonly minAccountSequence

64 bit account sequence

View Source js-stellar-base/src/transaction.js, line 161

number

# readonly minAccountSequenceAge

64 bit number of seconds

View Source js-stellar-base/src/transaction.js, line 173

number

# readonly minAccountSequenceLedgerGap

32 bit number of ledgers

View Source js-stellar-base/src/transaction.js, line 185

Array.<xdr.Operation>

# readonly operations

View Source js-stellar-base/src/transaction.js, line 230

string

# readonly sequence

View Source js-stellar-base/src/transaction.js, line 208

Array.<xdr.DecoratedSignature>

# readonly signatures

Overrides:

View Source js-stellar-base/src/transaction_base.js, line 26

object

# readonly timeBounds

Properties:
Name Type Description
64 string

bit unix timestamp

64 string

bit unix timestamp

View Source js-stellar-base/src/transaction.js, line 136

Methods

# addDecoratedSignature(signature) → {void}

Add a decorated signature directly to the transaction envelope.

Parameters:
Name Type Description
signature xdr.DecoratedSignature

raw signature to add

Overrides:
See:
  • Keypair.signDecorated
  • Keypair.signPayloadDecorated

View Source js-stellar-base/src/transaction_base.js, line 170

void

# addSignature(publicKey, signature) → {void}

Add a signature to the transaction. Useful when a party wants to pre-sign a transaction but doesn't want to give access to their secret keys. This will also verify whether the signature is valid.

Here's how you would use this feature to solicit multiple signatures.

  • Use TransactionBuilder to build a new transaction.
  • Make sure to set a long enough timeout on that transaction to give your signers enough time to sign!
  • Once you build the transaction, use transaction.toXDR() to get the base64-encoded XDR string.
  • Warning! Once you've built this transaction, don't submit any other transactions onto your account! Doing so will invalidate this pre-compiled transaction!
  • Send this XDR string to your other parties. They can use the instructions for getKeypairSignature to sign the transaction.
  • They should send you back their publicKey and the signature string from getKeypairSignature, both of which you pass to this function.
Parameters:
Name Type Description
publicKey string

The public key of the signer

signature string

The base64 value of the signature XDR

Overrides:

View Source js-stellar-base/src/transaction_base.js, line 129

void

# getClaimableBalanceId(opIndex) → {string}

Calculate the claimable balance ID for an operation within the transaction.

Parameters:
Name Type Description
opIndex integer

the index of the CreateClaimableBalance op

See:

View Source js-stellar-base/src/transaction.js, line 333

for invalid opIndex value

RangeError

if op at opIndex is not CreateClaimableBalance

TypeError

for general XDR un/marshalling failures

a hex string representing the claimable balance ID

string

# getKeypairSignature(keypair) → {string}

Signs a transaction with the given Keypair. Useful if someone sends you a transaction XDR for you to sign and return (see addSignature for more information).

When you get a transaction XDR to sign....

  • Instantiate a Transaction object with the XDR
  • Use Keypair to generate a keypair object for your Stellar seed.
  • Run getKeypairSignature with that keypair
  • Send back the signature along with your publicKey (not your secret seed!)

Example:

// `transactionXDR` is a string from the person generating the transaction
const transaction = new Transaction(transactionXDR, networkPassphrase);
const keypair = Keypair.fromSecret(myStellarSeed);
return transaction.getKeypairSignature(keypair);
Parameters:
Name Type Description
keypair Keypair

Keypair of signer

Overrides:

View Source js-stellar-base/src/transaction_base.js, line 101

Signature string

string

# hash() → {Buffer}

Returns a hash for this transaction, suitable for signing.

Overrides:

View Source js-stellar-base/src/transaction_base.js, line 198

Buffer

# sign(…keypairs) → {void}

Signs the transaction with the given Keypair.

Parameters:
Name Type Attributes Description
keypairs Keypair <repeatable>

Keypairs of signers

Overrides:

View Source js-stellar-base/src/transaction_base.js, line 71

void

# signHashX(preimage) → {void}

Add hashX signer preimage as signature.

Parameters:
Name Type Description
preimage Buffer | String

Preimage of hash used as signer

Overrides:

View Source js-stellar-base/src/transaction_base.js, line 179

void

# signatureBase() → {Buffer}

Returns the "signature base" of this transaction, which is the value that, when hashed, should be signed to create a signature that validators on the Stellar Network will accept.

It is composed of a 4 prefix bytes followed by the xdr-encoded form of this transaction.

View Source js-stellar-base/src/transaction.js, line 257

Buffer

# toEnvelope() → {xdr.TransactionEnvelope}

To envelope returns a xdr.TransactionEnvelope which can be submitted to the network.

View Source js-stellar-base/src/transaction.js, line 289

xdr.TransactionEnvelope

# toXDR() → {string}

Get the transaction envelope as a base64-encoded string

Overrides:

View Source js-stellar-base/src/transaction_base.js, line 214

XDR string

string