Skip to content

Commit

Permalink
docs(transaction): use explicit networkPassphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuukis committed Jul 26, 2019
1 parent de57e39 commit c648cc1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
19 changes: 10 additions & 9 deletions docs/reference/base-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ title: Transaction Examples
- [Creating an account](#creating-an-account)
- [Assets](#assets)
- [Path payment](#path-payment)
- [Multi-Signature account](#multi-signature-account)
- [Multi-signature account](#multi-signature-account)
- [Set up multisig account](#set-up-multisig-account)

## Creating an account

Expand All @@ -19,15 +20,14 @@ const server = new StellarSdk.Server('https://horizon-testnet.stellar.org')
const source = StellarSdk.Keypair.fromSecret('SA3W53XXG64ITFFIYQSBIJDG26LMXYRIMEVMNQMFAQJOYCZACCYBA34L')
const destination = StellarSdk.Keypair.random()

StellarSdk.Network.useTestNetwork()

server.accounts()
.accountId(source.publicKey())
.call()
.then(({ sequence }) => {
const account = new StellarSdk.Account(source.publicKey(), sequence)
const transaction = new StellarSdk.TransactionBuilder(account, {
fee: StellarSdk.BASE_FEE
fee: StellarSdk.BASE_FEE,
networkPassphrase: Networks.TESTNET
})
.addOperation(StellarSdk.Operation.createAccount({
destination: destination.publicKey(),
Expand Down Expand Up @@ -78,12 +78,12 @@ In the example below we're sending 1000 XLM (at max) from `GABJLI6IVBKJ7HIC5NN7H
The [path payment](https://www.stellar.org/developers/learn/concepts/list-of-operations.html#path-payment) will cause the destination address to get 5.5 GBP. It will cost the sender no more than 1000 XLM. In this example there will be 3 exchanges, XLM -> USD, USD-> EUR, EUR->GBP.

```js
StellarSdk.Network.useTestNetwork();
var keypair = StellarSdk.Keypair.fromSecret(secretString);

var source = new StellarSdk.Account(keypair.publicKey(), "46316927324160");
var transaction = new StellarSdk.TransactionBuilder(source, {
fee: StellarSdk.BASE_FEE
fee: StellarSdk.BASE_FEE,
networkPassphrase: Networks.TESTNET
})
.addOperation(StellarSdk.Operation.pathPayment({
sendAsset: StellarSdk.Asset.native(),
Expand Down Expand Up @@ -125,14 +125,14 @@ In each example, we'll use the root account.


```js
StellarSdk.Network.useTestNetwork();
var rootKeypair = StellarSdk.Keypair.fromSecret("SBQWY3DNPFWGSZTFNV4WQZLBOJ2GQYLTMJSWK3TTMVQXEY3INFXGO52X")
var account = new StellarSdk.Account(rootkeypair.publicKey(), "46316927324160");

var secondaryAddress = "GC6HHHS7SH7KNUAOBKVGT2QZIQLRB5UA7QAGLA3IROWPH4TN65UKNJPK";

var transaction = new StellarSdk.TransactionBuilder(account, {
fee: StellarSdk.BASE_FEE
fee: StellarSdk.BASE_FEE,
networkPassphrase: Networks.TESTNET
})
.addOperation(StellarSdk.Operation.setOptions({
signer: {
Expand All @@ -154,7 +154,8 @@ transaction.sign(rootKeypair); // only need to sign with the root signer as the
// now create a payment with the account that has two signers

var transaction = new StellarSdk.TransactionBuilder(account, {
fee: StellarSdk.BASE_FEE
fee: StellarSdk.BASE_FEE,
networkPassphrase: Networks.TESTNET
})
.addOperation(StellarSdk.Operation.payment({
destination: "GBTVUCDT5CNSXIHJTDHYSZG3YJFXBAJ6FM4CKS5GKSAWJOLZW6XX7NVC",
Expand Down
13 changes: 7 additions & 6 deletions docs/reference/building-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ The returned transaction will contain the sequence number of the source account.


```js
StellarSdk.Network.useTestNetwork();
// StellarBase.Network.usePublicNetwork(); if this transaction is for the public network
// Create an Account object from an address and sequence number.
var account=new StellarBase.Account("GD6WU64OEP5C4LRBH6NK3MHYIA2ADN6K6II6EXPNVUR3ERBXT4AN4ACD","2319149195853854");

var transaction = new StellarBase.TransactionBuilder(account, {
fee: StellarBase.BASE_FEE
fee: StellarBase.BASE_FEE,
networkPassphrase: Networks.TESTNET
})
// add a payment operation to the transaction
.addOperation(StellarBase.Operation.payment({
Expand Down Expand Up @@ -80,9 +80,10 @@ There are 5 types of memos:

```js
var memo = Memo.text('Happy birthday!');
var transaction = new StellarBase.TransactionBuilder(account, {
var transaction = new StellarBase.TransactionBuilder(account, {
memo: memo,
fee: StellarBase.BASE_FEE
fee: StellarBase.BASE_FEE,
networkPassphrase: Networks.TESTNET
})
.addOperation(StellarBase.Operation.payment({
destination: "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW",
Expand Down Expand Up @@ -142,15 +143,15 @@ var keypair = Keypair.random();


```js
StellarBase.Network.useTestNetwork();
var key1 = Keypair.fromSecret('SBK2VIYYSVG76E7VC3QHYARNFLY2EAQXDHRC7BMXBBGIFG74ARPRMNQM');
var key2 = Keypair.fromSecret('SAMZUAAPLRUH62HH3XE7NVD6ZSMTWPWGM6DS4X47HLVRHEBKP4U2H5E7');

// Create an Account object from an address and sequence number.
var account=new StellarBase.Account("GD6WU64OEP5C4LRBH6NK3MHYIA2ADN6K6II6EXPNVUR3ERBXT4AN4ACD","2319149195853854");

var transaction = new StellarBase.TransactionBuilder(account, {
fee: StellarBase.BASE_FEE
fee: StellarBase.BASE_FEE,
networkPassphrase: Networks.TESTNET
})
.addOperation(StellarBase.Operation.payment({
destination: "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW",
Expand Down
2 changes: 1 addition & 1 deletion src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Transaction {
* Example:
* ```javascript
* // `transactionXDR` is a string from the person generating the transaction
* const transaction = new Transaction(transactionXDR);
* const transaction = new Transaction(transactionXDR, networkPassphrase);
* const keypair = Keypair.fromSecret(myStellarSeed);
* return transaction.getKeypairSignature(keypair);
* ```
Expand Down
30 changes: 15 additions & 15 deletions src/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export const TimeoutInfinite = 0;
* the desired operations, call the `build()` method on the `TransactionBuilder` to return a fully
* constructed `{@link Transaction}` that can be signed. The returned transaction will contain the
* sequence number of the source account and include the signature from the source account.</p>
*
*
* <p><strong>Be careful about unsubmitted transactions!</strong> When you build a transaction, stellar-sdk
* automatically increments the source account's sequence number. If you end up
* automatically increments the source account's sequence number. If you end up
* not submitting this transaction and submitting another one instead, it'll fail due to
* the sequence number being wrong. So if you decide not to use a built transaction,
* make sure to update the source account's sequence number
* make sure to update the source account's sequence number
* with [Server.loadAccount](https://stellar.github.io/js-stellar-sdk/Server.html#loadAccount) before creating another transaction.</p>
*
* <p>The following code example creates a new transaction with {@link Operation.createAccount} and
Expand All @@ -43,18 +43,18 @@ export const TimeoutInfinite = 0;
* a payment to `destinationB`. The built transaction is then signed by `sourceKeypair`.</p>
*
* ```
* var transaction = new TransactionBuilder(source, { fee })
* .addOperation(Operation.createAccount({
destination: destinationA,
startingBalance: "20"
})) // <- funds and creates destinationA
.addOperation(Operation.payment({
destination: destinationB,
amount: "100",
asset: Asset.native()
})) // <- sends 100 XLM to destinationB
* .setTimeout(30)
* .build();
* var transaction = new TransactionBuilder(source, { fee, networkPassphrase: Networks.TESTNET })
* .addOperation(Operation.createAccount({
* destination: destinationA,
* startingBalance: "20"
* })) // <- funds and creates destinationA
* .addOperation(Operation.payment({
* destination: destinationB,
* amount: "100",
* asset: Asset.native()
* })) // <- sends 100 XLM to destinationB
* .setTimeout(30)
* .build();
*
* transaction.sign(sourceKeypair);
* ```
Expand Down

0 comments on commit c648cc1

Please sign in to comment.