stellar-sdk
Advanced tools
Changelog
This is a direct re-tag of rc.2 with the only change being an upgrade to the stellar-base
library to incorporate a patch release. Nonetheless, the entire changelog from the prior major version here is replicated for a comprehensive view on what's broken, added, and fixed.
contract
module.contract.AssembledTransaction#signAuthEntries
now takes an address
instead of a publicKey
. This brings the API more inline with its actual functionality: It can be used to sign all the auth entries for a particular address, whether that is the address of an account (public key) or a contract. (#1044).ClientOptions.signTransaction
type has been updated to reflect the latest SEP-43 protocol, which matches the latest major version of Freighter and other wallets. It now accepts address
, submit
, and submitUrl
options, and it returns a promise containing the signedTxXdr
and the signerAddress
. It now also returns an Error
type if an error occurs during signing.
basicNodeSigner
has been updated to reflect this new type.ClientOptions.signAuthEntry
type has been updated to reflect the SEP-43 protocol, which returns a promise containing the signerAddress
in addition to the signAuthEntry
that was returned previously. It also can return an Error
type.SentTransaction.init
and new SentTransaction
now take one (1) argument instead of two (2). The first argument had previously been deprecated and ignored. To update:-SentTransaction(nonsense, realStuff)
+SentTransaction(realStuff)
-new SentTransaction(nonsense, realStuff)
+new SentTransaction(realStuff)
rpc
and Horizon
modules.simulateTransaction
's cost
field is removedrpc.Server.getEvents
's pagingToken
field is deprecated, use cursor
insteadtransaction_count
, base_fee
, and base_reserve
num_accounts
and amount
from assetsSorobanRpc
import, previously deprecated, has been removed. You can import rpc
instead:-import { SorobanRpc } from '@stellar/stellar-sdk'
+import { rpc } from '@stellar/stellar-sdk'
// alternatively, you can also import from the `rpc` entrypoint:
import { Server } from '@stellar/stellar-sdk/rpc'
contract
module.contract.Client
now has a static deploy
method that can be used to deploy a contract instance from an existing uploaded/"installed" Wasm hash. The first arguments to this method are the arguments for the contract's __constructor
method in accordance with CAP-42 (#1086). For example, using the increment
test contract as modified in https://github.com/stellar/soroban-test-examples/pull/2/files#diff-8734809100be3803c3ce38064730b4578074d7c2dc5fb7c05ca802b2248b18afR10-R45:const tx = await contract.Client.deploy(
{ counter: 42 },
{
networkPassphrase,
rpcUrl,
wasmHash: uploadedWasmHash,
publicKey: someKeypair.publicKey(),
...basicNodeSigner(someKeypair, networkPassphrase),
},
);
const { result: client } = await tx.signAndSend();
const t = await client.get();
expect(t.result, 42);
contract.AssembledTransaction#signAuthEntries
now allows you to override authorizeEntry
. This can be used to streamline novel workflows using cross-contract auth. (#1044).rpc
, Horizon
, and stellartoml
modules.Horizon.ServerApi
now has an EffectType
exported so that you can compare and infer effect types directly (#1099).Horizon.ServerApi.Trade
type now has a type_i
field for type inference (#1099).stellartoml.Resolver.resolve
now has a allowedRedirects
option to configure the number of allowed redirects to follow when resolving a stellar toml file.rpc.Server.getEvents
now returns a cursor
field that matches pagingToken
and id
rpc.Server.getTransactions
now returns a txHash
fieldrpc.Server
has two new methods:
pollTransaction
to retry transaction retrieval ([#1092]https://github.com/stellar/js-stellar-sdk/pull/1092), andgetSACBalance
to fetch the balance of a built-in Stellar Asset Contract token held by a contract (#1046), returning this schema:export interface BalanceResponse {
latestLedger: number;
/** present only on success, otherwise request malformed or no balance */
balanceEntry?: {
/** a 64-bit integer */
amount: string;
authorized: boolean;
clawback: boolean;
lastModifiedLedgerSeq?: number;
liveUntilLedgerSeq?: number;
};
}
USE_AXIOS=false
to build without the axios
dependency: this will build stellar-sdk-no-axios.js
and stellar-sdk-no-axios.min.js
in the dist/
directory, or just run yarn build:browser:no-axios
to generate these files.axios
dependency via @stellar/stellar-sdk/no-axios
. For Node environments that don't support modern imports, use @stellar/stellar-sdk/lib/no-axios/index
.USE_EVENTSOURCE=false
to build without the eventsource
dependency: this will build stellar-sdk-no-eventsource.js
and stellar-sdk-no-eventsource.min.js
in the dist/
directory, or just run yarn build:browser:no-eventsource
to generate these files.eventsource
dependency via @stellar/stellar-sdk/no-eventsource
. For Node.js environments that don't support modern imports, use @stellar/stellar-sdk/lib/no-eventsource/index
.stellar-sdk-minimal.js
for the browser build and import from @stellar/stellar-sdk/minimal
for the Node package.contract.AssembledTransaction#nonInvokerSigningBy
now correctly returns contract addresses, in instances of cross-contract auth, rather than throwing an error. sign
will ignore these contract addresses, since auth happens via cross-contract call (#1044).buildInvocationTree
now correctly handles V2 contract creation and displays constructor args (js-stellar-base#785).Changelog
ClientOptions.signTransaction
type has been updated to reflect the latest SEP-43 protocol, which matches the latest major version of Freighter and other wallets. It now accepts address
, submit
, and submitUrl
options, and it returns a promise containing the signedTxXdr
and the signerAddress
. It now also returns an Error
type if an error occurs during signing.
basicNodeSigner
has been updated to reflect the new type.ClientOptions.signAuthEntry
type has also been updated to reflect the SEP-43 protocol, which also returns a promise containing the signerAddress
in addition to the signAuthEntry
that was returned previously. It also can return an Error
type.contract.Client
now has a static deploy
method that can be used to deploy a contract instance from an existing uploaded/"installed" Wasm hash. The first arguments to this method are the arguments for the contract's __constructor
method in accordance with CAP-42 (#1086).For example, using the increment
test contract as modified in https://github.com/stellar/soroban-test-examples/pull/2/files#diff-8734809100be3803c3ce38064730b4578074d7c2dc5fb7c05ca802b2248b18afR10-R45:
const tx = await contract.Client.deploy(
{ counter: 42 },
{
networkPassphrase,
rpcUrl,
wasmHash: uploadedWasmHash,
publicKey: someKeypair.publicKey(),
...basicNodeSigner(someKeypair, networkPassphrase),
},
);
const { result: client } = await tx.signAndSend();
const t = await client.get();
expect(t.result, 42);
Horizon.ServerApi
now has an EffectType
exported so that you can compare and infer effect types directly (#1099).Horizon.ServerApi.Trade
type now has a type_i
field for type inference.stellartoml-Resolver.resolve
now has a allowedRedirects
option to configure the number of allowed redirects to follow when resolving a stellar toml file.Changelog
Deprecated RPC APIs have been removed (#1084):
simulateTransaction
's cost
field is removedgetEvents
returns a cursor
field that matches pagingToken
and id
getTransactions
returns a txHash
fieldHorizon Server API types: removed fields transaction_count
, base_fee
, and base_reserve
(deprecated since v10.0.1)
SentTransaction.init
and new SentTransaction
now take one (1) argument instead of two (2). The first argument had previously been deprecated and ignored. To update:
-SentTransaction(nonsense, realStuff)
+SentTransaction(realStuff)
-new SentTransaction(nonsense, realStuff)
+new SentTransaction(realStuff)
SorobanRpc
import, previously deprecated, has been removed. You can import rpc
instead:
-import { SorobanRpc } from '@stellar/stellar-sdk'
+import { rpc } from '@stellar/stellar-sdk'
As an alternative, you can also import from the rpc
entrypoint:
import { Server } from '@stellar/stellar-sdk/rpc'
rpc.Server
now has a pollTransaction
method to retry transaction retrieval ([#1092]https://github.com/stellar/js-stellar-sdk/pull/1092).Changelog
contract.AssembledTransaction#signAuthEntries
now takes an address
instead of a publicKey
. This brings the API more inline with its actual functionality: It can be used to sign all the auth entries for a particular address, whether that is the address of an account (public key) or a contract. (#1044).USE_AXIOS=false
to build without the axios
dependency: this will build stellar-sdk-no-axios.js
and stellar-sdk-no-axios.min.js
in the dist/
directory, or just run yarn build:browser:no-axios
to generate these files.axios
dependency via @stellar/stellar-sdk/no-axios
. For Node environments that don't support modern imports, use @stellar/stellar-sdk/lib/no-axios/index
.USE_EVENTSOURCE=false
to build without the eventsource
dependency: this will build stellar-sdk-no-eventsource.js
and stellar-sdk-no-eventsource.min.js
in the dist/
directory, or just run yarn build:browser:no-eventsource
to generate these files.eventsource
dependency via @stellar/stellar-sdk/no-eventsource
. For Node.js environments that don't support modern imports, use @stellar/stellar-sdk/lib/no-eventsource/index
.stellar-sdk-minimal.js
for the browser build and import from @stellar/stellar-sdk/minimal
for the Node package.contract.AssembledTransaction#signAuthEntries
now allows you to override authorizeEntry
. This can be used to streamline novel workflows using cross-contract auth. (#1044)rpc.Server
now has a getSACBalance
helper which lets you fetch the balance of a built-in Stellar Asset Contract token held by a contract (#1046):export interface BalanceResponse {
latestLedger: number;
/** present only on success, otherwise request malformed or no balance */
balanceEntry?: {
/** a 64-bit integer */
amount: string;
authorized: boolean;
clawback: boolean;
lastModifiedLedgerSeq?: number;
liveUntilLedgerSeq?: number;
};
}
contract.AssembledTransaction#nonInvokerSigningBy
now correctly returns contract addresses, in instances of cross-contract auth, rather than throwing an error. sign
will ignore these contract addresses, since auth happens via cross-contract call (#1044).Changelog
rpc.Server
now has a getTransactions
, which has the same response schema as getTransactions
except with bundles of transactions (#1037).rpc.Server
now has a getVersionInfo
method which reports version information of the RPC instance it is connected to (#1028):export interface GetVersionInfoResponse {
version: string;
commit_hash: string;
build_time_stamp: string;
captive_core_version: string;
protocol_version: number;
}
statusText
error check to broaden compatibility (#1001).stellar-base
which includes various fixes (release notes, #1045).Changelog
@stellar/stellar-base
and its underlying dependency @stellar/js-xdr
have been upgraded to their latest versions; reference their release notes (v12.1.0 and v3.1.2, respectively) for details (#1013).rpc.Server
and Horizon.Server
(#1013):import { Server } from "@stellar/stellar-sdk/rpc";
const s = new Server("<some URL>", { headers: { "X-Custom-Header": "hello" }})
Horizon.Server
now supports the new POST /transactions_async
endpoint via the submitAsyncTransaction
method (#989). Its purpose is to provide an immediate response to the submission rather than waiting for Horizon to determine its status. The response schema is as follows:interface SubmitAsyncTransactionResponse {
// the submitted transaction hash
hash: string;
// one of "PENDING", "DUPLICATE", "TRY_AGAIN_LATER", or "ERROR"
tx_status: string;
// a base64-encoded xdr.TransactionResult iff `tx_status` is "ERROR"
error_result_xdr: string;
}
rpc.Server
now has a getFeeStats
method which retrieves fee statistics for a previous chunk of ledgers to provide users with a way to provide informed decisions about getting their transactions included in the following ledgers (#998):export interface GetFeeStatsResponse {
sorobanInclusionFee: FeeDistribution;
inclusionFee: FeeDistribution;
latestLedger: number; // uint32
}
interface FeeDistribution {
max: string; // uint64
min: string; // uint64
mode: string; // uint64
p10: string; // uint64
p20: string; // uint64
p30: string; // uint64
p40: string; // uint64
p50: string; // uint64
p60: string; // uint64
p70: string; // uint64
p80: string; // uint64
p90: string; // uint64
p95: string; // uint64
p99: string; // uint64
transactionCount: string; // uint32
ledgerCount: number; // uint32
}
Changelog
contract
now exports the DEFAULT_TIMEOUT
(#984).contract.AssembledTransaction
now has:
toXDR
and fromXDR
methods for serializing the transaction to and from XDR. These methods should be used in place of AssembledTransaction.toJSON
and AssembledTransaction.fromJSON
for multi-auth signing. The JSON methods are now deprecated. Note: you must now call simulate
on the transaction before the final signAndSend
call after all required signatures are gathered when using the XDR methods (#977).restoreFootprint
method which accepts the restorePreamble
returned when a simulation call fails due to some contract state that has expired. When invoking a contract function, one can now set restore
to true
in the MethodOptions
. When enabled, a restoreFootprint
transaction will be created and await signing when required (#991).sign
and send
methods so that you can sign a transaction without sending it (signAndSend
still works as before; #922).contract.Client
now has a txFromXDR
method which should be used in place of txFromJSON
for multi-auth signing (#977).contract.AssembledTransaction
, toJSON
and fromJSON
should be replaced with toXDR
and fromXDR
.contract.Client
, txFromJSON
should be replaced with txFromXDR
.AssembledTransaction
with tx.raw = cloneFrom(tx.build)
, the tx.simulationData
will now be updated correctly (#985).Changelog
v12.0.0-rc.3
with dependency updates and a single new feature.rpc.server.simulateTransaction
now supports an optional stateChanges?: LedgerEntryChange[]
field (#963):
Before
is omitted, it constitutes a creation, if After
is omitted, it constitutes a deletions, note that Before
and After
cannot be omitted at the same time. Each item follows this schema:interface LedgerEntryChange {
type: number;
key: xdr.LedgerKey;
before: xdr.LedgerEntry | null;
after: xdr.LedgerEntry | null;
}
Changelog
ContractClient
functionality previously added in v11.3.0 was exported in a non-standard way. You can now import it as any other stellar-sdk
module (#962):-import { ContractClient } from '@stellar/stellar-sdk/lib/contract_client'
+import { contract } from '@stellar/stellar-sdk'
+const { Client } = contract
Note that this top-level contract
export is a container for ContractClient and related functionality. The ContractClient
class is now available at contract.Client
, as shown. Further note that there is a capitalized Contract
export as well, which comes from stellar-base. You can remember which is which because capital-C Contract
is a class, whereas lowercase-c contract
is a container/module with a bunch of classes, functions, and types.
Additionally, this is available from the /contract
entrypoint, if your version of Node and TypeScript support the exports
declaration. Finally, some of its exports have been renamed:
import {
- ContractClient,
+ Client,
AssembledTransaction,
- ContractClientOptions,
+ ClientOptions,
SentTransaction,
-} from '@stellar/stellar-sdk/lib/contract_client'
+} from '@stellar/stellar-sdk/contract'
ContractSpec
class is now nested under the contract
module, and has been renamed to Spec
(#962). Alternatively, you can import this from the contract
entrypoint, if your version of Node and TypeScript support the exports
declaration:-import { ContractSpec } from '@stellar/stellar-sdk'
+import { contract } from '@stellar/stellar-sdk'
+const { Spec } = contract
// OR
+import { Spec } from '@stellar/stellar-sdk/contract'
AssembledTransaction.signAndSend()
would return a SentTransaction
even if the transaction was never finalized. That is, if it successfully sent the transaction to the network, but the transaction was still status: 'PENDING'
, then it would console.error
an error message, but return the indeterminate transaction anyhow. It now throws a SentTransaction.Errors.TransactionStillPending
error with that error message instead (#962).SorobanRpc
module is now also exported as rpc
(#962). You can import it with either name for now, but SorobanRpc
will be removed in a future release:-import { SorobanRpc } from '@stellar/stellar-sdk'
+import { rpc } from '@stellar/stellar-sdk'
You can also now import it at the /rpc
entrypoint, if your version of Node and TypeScript support the exports
declaration.
-import { SorobanRpc } from '@stellar/stellar-sdk'
-const { Api } = SorobanRpc
+import { Api } from '@stellar/stellar-sdk/rpc'
contract.Client
(#960):
from(opts: ContractClientOptions)
instantiates contract.Client
by fetching the contractId
's WASM from the network to fill out the client's ContractSpec
.fromWasm
and fromWasmHash
methods to instantiate a contract.Client
when you already have the WASM bytes or hash alongside the contract.ClientOptions
.rpc.Server
(#960):
getContractWasmByContractId
and getContractWasmByHash
to retrieve a contract's WASM bytecode via its contractId
or wasmHash
, respectively.contract
module to be used in non-Node environments.