Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions docs/build/guides/archival/restore-contract-js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
Networks,
TransactionBuilder,
SorobanDataBuilder,
Operation
Operation,
xdr,
} from "@stellar/stellar-sdk";
import { Server, Api } from "@stellar/stellar-sdk/rpc";

Expand All @@ -44,19 +45,14 @@ async function restoreContract(
const instance = c.getFootprint();

const account = await server.getAccount(signer.publicKey());
const wasmEntry = await server.getLedgerEntries(
getWasmLedgerKey(instance)
);
const wasmEntry = await server.getLedgerEntries(getWasmLedgerKey(instance));

const restoreTx = new TransactionBuilder(account, { fee: BASE_FEE })
.setNetworkPassphrase(Networks.TESTNET)
.setSorobanData(
// Set the restoration footprint (remember, it should be in the
// read-write part!)
new SorobanDataBuilder().setReadWrite([
instance,
wasmEntry
]).build(),
new SorobanDataBuilder().setReadWrite([instance, wasmEntry]).build(),
)
.addOperation(Operation.restoreFootprint({}))
.build();
Expand All @@ -66,11 +62,11 @@ async function restoreContract(
return submitTx(preppedTx);
}

function getWasmLedgerKey(entry: xdr.ContractDataEntry): {
function getWasmLedgerKey(entry: xdr.ContractDataEntry): xdr.LedgerKey {
return xdr.LedgerKey.contractCode(
new xdr.LedgerKeyContractCode({
hash: entry.val().instance().wasmHash()
})
hash: entry.val().instance().wasmHash(),
}),
);
}
```
8 changes: 4 additions & 4 deletions docs/build/guides/basics/automate-reset-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Automating blockchain state on Stellar's Testnet and Futurenet can streamline de

```javascript
import {
Asset,
Networks,
Keypair,
TransactionBuilder,
Expand All @@ -59,6 +60,7 @@ import {
LiquidityPoolAsset,
LiquidityPoolFeeV18,
BASE_FEE,
nativeToScVal,
} from "@stellar/stellar-sdk";
import { Server, Api } from "@stellar/stellar-sdk/rpc";
import fs from "fs";
Expand Down Expand Up @@ -177,7 +179,7 @@ async function createLiquidityPool(accountKeypair, nativeAsset, customAsset) {

const transaction = new TransactionBuilder(account, {
fee: BASE_FEE,
networkPassphrase: networkPassPhrase,
networkPassphrase,
})
.addOperation(
Operation.changeTrust({
Expand Down Expand Up @@ -260,9 +262,7 @@ async function deployAndInvokeContract(deployer, contractWasmFilePath) {
}
console.log(`Contract Deployed...`);

const contractAddr = Address.fromScAddress(
returnContractResponse.returnValue.address(),
);
const contractAddr = Address.fromScAddress(status.returnValue.address());
const contractId = contractAddr.toString();
const contract = new Contract(contractId);

Expand Down
2 changes: 1 addition & 1 deletion docs/build/guides/transactions/path-payments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ let transaction = new TransactionBuilder(account, {
.build();

transaction.sign(receiverKP);
const resp = await SERVER.submitTransaction(transaction);
const resp = await horizonServer.submitTransaction(transaction);
console.log("resp", resp);
```

Expand Down
4 changes: 2 additions & 2 deletions docs/build/guides/transactions/submit-transaction-wait-js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ async function submitTx(
switch (finalStatus.status) {
case Api.GetTransactionStatus.FAILED:
case Api.GetTransactionStatus.NOT_FOUND:
throw tmpStatus;
throw finalStatus;
case Api.GetTransactionStatus.SUCCESS:
return status;
return finalStatus;
}
});
}
Expand Down
45 changes: 31 additions & 14 deletions docs/data/apis/horizon/api-reference/errors/error-handling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ curl -s https://horizon-testnet.stellar.org/claimable_balances/0000 | jq '.extra

</CodeExample>

Note that the SDKs make it a point to distinguish an invalid request (as above) versus a missing resource (a `404 Not Found`) (for example, the generic `NetworkError` versus a `NotFoundError` in the JavaScript SDK), where the latter might not be considered an error depending on your situation.
Note that the SDKs make it a point to distinguish an invalid request (as above) versus a missing resource (a `404 Not Found`) (for example, the generic `NetworkError` versus a `NotFoundError` in the JavaScript SDK), where the latter might not be considered an error depending on your situation. For JavaScript-specific guidance, see the [JavaScript SDK error handling guide](https://stellar.github.io/js-stellar-sdk/guides/05-handle-errors/).

## Error Handling for Transaction Submissions

Expand Down Expand Up @@ -66,7 +66,9 @@ Submissions using the `/transactions_async` endpoint return an immediate respons
<CodeExample>

```js
let server = sdk.Server("https://horizon-testnet.stellar.org");
let server = new StellarSdk.Horizon.Server(
"https://horizon-testnet.stellar.org",
);
let contractId = "CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE";
let contract = new StellarSdk.Contract(contractId);

Expand Down Expand Up @@ -94,7 +96,7 @@ server.submitAsyncTransaction(transaction).then((result) => {
});

// Add a small sleep duration before polling the transaction.
time.sleep(5 * time.Second);
await new Promise((resolve) => setTimeout(resolve, 5000));
server
.transactions()
.transaction(result.hash)
Expand Down Expand Up @@ -133,9 +135,11 @@ Example implementation:
<CodeExample>

```js
import { Horizon } from "@stellar/stellar-sdk";
import * as StellarSdk from "@stellar/stellar-sdk";

let server = Horizon.Server("https://horizon-testnet.stellar.org");
let server = new StellarSdk.Horizon.Server(
"https://horizon-testnet.stellar.org",
);

function submitTransaction(tx, timeout) {
if (!tx.timeBounds || tx.timeBounds.maxTime === 0) {
Expand Down Expand Up @@ -174,18 +178,31 @@ These errors typically occur when you have an outdated view of an account. This

```js
// suppose `account` is an outdated `AccountResponse` object
let tx = sdk.TransactionBuilder(account, ...)/* etc */.build();
let tx = new StellarSdk.TransactionBuilder(account, {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET,
})
/* etc */
.build();
server.submitTransaction(tx).catch(function (error) {
if (error.response && error.status == 400 && error.extras &&
error.extras.result_codes.transaction == sdk.TX_BAD_SEQ) {
return server.loadAccount(account.accountId())
.then(function (response) {
let tx = sdk.TransactionBuilder(response, ...)/* etc */.build()
return server.submitTransaction(tx);
});
if (
error.response &&
error.status == 400 &&
error.extras &&
error.extras.result_codes.transaction == StellarSdk.TX_BAD_SEQ
) {
return server.loadAccount(account.accountId()).then(function (response) {
let tx = new StellarSdk.TransactionBuilder(response, {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET,
})
/* etc */
.build();
return server.submitTransaction(tx);
});
}
// ...other error conditions...
})
});
```

</CodeExample>
Expand Down
4 changes: 4 additions & 0 deletions docs/data/apis/rpc/api-reference/methods/getLedgerEntries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ Much like an [account](#accounts), the resulting entry has a balance, but it als
<CodeExample>

```typescript
import { Asset, AssetType, xdr } from "@stellar/stellar-sdk";

let asset: string;
let rawAsset = trustlineEntryData.asset();

Expand Down Expand Up @@ -384,6 +386,8 @@ Once we've learned to _build_ and _parse_ these (which we've done above at lengt
<CodeExample>

```typescript
import { Server } from "@stellar/stellar-sdk/rpc";

const s = new Server("https://soroban-testnet.stellar.org");

// assume key1 is an account, key2 is a trustline, and key3 is contract data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ npm install --save @stellar/stellar-sdk
const {
Keypair,
Contract,
rpc as StellarRpc,
rpc: StellarRpc,
TransactionBuilder,
Networks,
BASE_FEE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ In this variant, we will leverage the "source account authorization" variant: th
```javascript
import {
Asset,
BASE_FEE,
Keypair,
Networks,
Operation,
authorizeEntry,
nativeToScVal,
TransactionBuilder,
xdr,
} from "@stellar/stellar-sdk";
import { Server, assembleTransaction } from "@stellar/stellar-sdk/rpc";

const s = Server("https://soroban-testnet.stellar.org");
const s = new Server("https://soroban-testnet.stellar.org");

// Pretend is is a real, funded account.
const signer = Keypair.random();
Expand Down Expand Up @@ -116,17 +118,20 @@ In this variant, we'll extend the required signatures to more than one party, so

```typescript
import {
Address,
Asset,
BASE_FEE,
Keypair,
Networks,
Operation,
authorizeEntry,
nativeToScVal,
TransactionBuilder,
xdr,
} from "@stellar/stellar-sdk";
import { Server, assembleTransaction } from "@stellar/stellar-sdk/rpc";

const s = Server("https://soroban-testnet.stellar.org");
const s = new Server("https://soroban-testnet.stellar.org");

// Pretend these are real, funded accounts.
const signers = [Keypair.random(), Keypair.random()];
Expand Down Expand Up @@ -176,7 +181,7 @@ async function main() {
).toString() === signer.publicKey(),
)
: null,
response.latestLedger + 12, // signature is valid for ~1m
simResult.latestLedger + 12, // signature is valid for ~1m
Networks.TESTNET,
),
);
Expand Down
6 changes: 5 additions & 1 deletion docs/tokens/how-to-issue-an-asset.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ First, you must generate a unique keypair. The public key will act as your [issu
<CodeExample>

```js
import * as StellarSdk from "@stellar/stellar-sdk";

const issuerKeypair = StellarSdk.Keypair.random();

console.log("Issuer Public Key:", issuerKeypair.publicKey());
Expand Down Expand Up @@ -115,7 +117,9 @@ distributorKeypair := keypair.MustRandom()
<CodeExample>

```js
const distributorKeypair = StellarSdk.Keypair.fromSecret(‘SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4’)
const distributorKeypair = StellarSdk.Keypair.fromSecret(
"SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4",
);
```

```python
Expand Down