Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Reworked documentation of Soroban RPC methods using open-rpc-docs-react component to be consistent with Anchor API #603

Merged
merged 5 commits into from
Oct 18, 2023
Merged
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
53 changes: 3 additions & 50 deletions api/methods/getEvents.mdx
Original file line number Diff line number Diff line change
@@ -1,59 +1,12 @@
---
sidebar_position: 2
hide_title: true
---

import ExampleRequest from "@site/src/components/ExampleRequest";
import {RpcMethod} from "@site/src/components/RpcMethod";

Clients can request a filtered list of events emitted by a given ledger range.

Soroban-RPC will support querying within a maximum 24 hours of recent ledgers.

Note, this could be used by the client to only prompt a refresh when there is a new ledger with relevant events. It should also be used by backend Dapp components to "ingest" events into their own database for querying and serving.

If making multiple requests, clients should deduplicate any events received, based on the event's unique id field. This prevents double-processing in the case of duplicate events being received.

By default soroban-rpc retains the most recent 24 hours of events.

## Parameters

- `startLedger`: `<string>` - Stringified ledger sequence number to fetch events after (inclusive). This method will return an error if `startLedger` is less than the oldest ledger stored in this node, or greater than the latest ledger seen by this node. If a [cursor](../pagination) is included in the request, `startLedger` must be omitted.
- `filters`: `<object[]>` - List of filters for the returned events. Events matching any of the filters are included. To match a filter, an event must match both a contractId and a topic. Maximum 5 filters are allowed per request.
- `type`: `<string>` - (optional) A comma separated list of event types (`system`, `contract`, or `diagnostic`) used to filter events. If omitted, all event types are included.
- `contractIds`: `<string[]>` - (optional) List of contract ids to query for events. If omitted, return events for all contracts. Maximum 5 contract IDs are allowed per request.
- `topics`: `<TopicFilter[]>` - (optional) List of topic filters. If omitted, query for all events. If multiple filters are specified, events will be included if they match any of the filters. Maximum 5 filters are allowed per request.
- A `TopicFilter` is `SegmentMatcher[]`
- The list can be 1-4 `SegmentMatcher`s long.
- A `SegmentMatcher` is one of the following:
- For an exact segment match, a string containing base64-encoded ScVal
- For a wildcard single-segment match, the string "*", matches exactly one segment.
- Examples of matching token transfer events. Events are emitted here: [rs-soroban-env/event.rs @ `924d86c`], with base64-encoded ScVals decoded for easier reading (both the symbols and addresses). In real usage, the `ScSymbol("transfer").toXdr().toString("base64")`, and `ScBinary(pubkeyBytes).toXdr().toString("base64")`, would be base64-encoded strings for exact matches. For example:
- `[ScSymbol("transfer"), "*", "*"]`
- Matches any token transfer events
- `[ScSymbol("transfer"), "*", "GABC...123"]`
- Matches any token transfer events to recipient: GABC...123
- `[ScSymbol("transfer"), "GDEF...456", "GABC...123"]`
- Matches only token transfers from GDEF...456 to GABC...123.
- `pagination`: `<PaginationOptions>` - See "[Pagination](../pagination)"

## Returns

- `<object>`
- `latestLedger`: `<string>` - Stringified-number of the current latest ledger observed by the node when this response was generated.
- `events`: `<object[]>`
- `ledger`: `<string>` - String-ified sequence number of the ledger.
- `ledgerClosedAt`: `<string>` - [ISO-8601](https://www.iso.org/iso-8601-date-and-time-format.html) timestamp of the ledger closing time.
- `contractId`: `<string>` - StrKey ID (`C...`) of the emitting contract ([SEP-23](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md#specification)).
- `id`: `<string>` - Unique identifier for this event.
- The event's unique id field is based on a [`toid` from Horizon] as used in Horizon's /effects endpoint.
- https://github.com/stellar/go/blob/master/services/horizon/internal/db2/history/effect.go#L58
- Specifically, it is a string containing:
- bigint(32 bit ledger sequence + 20 bit txn number + 12 bit operation) + `<hyphen>` + number for the event within the operation.
- For example: `1234-1`
- `pagingToken`: `<string>` - Duplicate of `id` field, but in the standard place for pagination tokens.
- `inSuccessfulContractCall`: `<boolean>` - If true the event was emitted during a successful contract call.
- `topic`: `<xdr.ScVal[]>` - List containing the topic this event was emitted with.
- `value`: `<object>` - List containing the topic this event was emitted with.
- `xdr`: `<xdr.ScVal>` - The emitted body value of the event (serialized in a base64 string).
<RpcMethod method="getEvents"/>

## Examples

Expand Down
12 changes: 3 additions & 9 deletions api/methods/getHealth.mdx
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
---
sidebar_position: 3
hide_title: true
---

import ExampleRequest from "@site/src/components/ExampleRequest";

General node health check.
import {RpcMethod} from "@site/src/components/RpcMethod";

## Parameters

- None

## Returns

- `<object>`
- `status`: "healthy"
<RpcMethod method="getHealth"/>

## Examples

Expand Down
14 changes: 3 additions & 11 deletions api/methods/getLatestLedger.mdx
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
---
sidebar_position: 1
hide_title: true
---

import ExampleRequest from "@site/src/components/ExampleRequest";

For finding out the current latest known ledger of this node. This is a subset of the ledger info from Horizon.
import {RpcMethod} from "@site/src/components/RpcMethod";

## Parameters

- None

## Returns

- `<object>`
- `id`: `<hash>` - hash of the latest ledger as a hex-encoded string
- `protocolVersion`: `<number>` - Stellar Core protocol version associated with the latest ledger
- `sequence`: `<number>` - sequence number of the latest ledger
<RpcMethod method="getLatestLedger"/>

## Examples

Expand Down
22 changes: 3 additions & 19 deletions api/methods/getLedgerEntries.mdx
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
---
sidebar_position: 4
hide_title: true
---

import ExampleRequest from "@site/src/components/ExampleRequest";
import {RpcMethod} from "@site/src/components/RpcMethod";

For reading the current value of ledger entries directly.

Allows you to directly inspect the _current state_ of a contract, a contract's code, or any other ledger entry. This is a backup way to access your contract data which may not be available via events or `simulateTransaction`.

To fetch contract wasm byte-code, use the ContractCode ledger entry key.

## Parameters

- `keys`: `<xdr.LedgerKey[]>` - Array containing the keys of the ledger entries you wish to retrieve. (an array of serialized base64 strings)

## Return

- `<object>`
- `entries`: Array containing the specified ledger entries which were found.
- `key`: `<xdr.LedgerKey>` - The key of the ledger entry (serialized in a base64 string).
- `xdr`: `<xdr.LedgerEntryData>` - The current value of the given ledger entry (serialized in a base64 string).
- `lastModifiedLedgerSeq`: `<string>` - The ledger sequence number of the last time this entry was updated.
- `expirationLedgerSeq`: `<string>` - The ledger sequence number after which the ledger entry would expire. This field exists only for ContractCodeEntry and ContractDataEntry ledger entries (optional).
- `latestLedger`: `<number>` - The current latest ledger observed by the node when this response was generated.
<RpcMethod method="getLedgerEntries"/>

## Examples

Expand Down
14 changes: 3 additions & 11 deletions api/methods/getNetwork.mdx
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
---
sidebar_position: 5
hide_title: true
---

import ExampleRequest from "@site/src/components/ExampleRequest";

General info about the currently configured network.
import {RpcMethod} from "@site/src/components/RpcMethod";

## Parameters

- None

## Returns

- `<object>`
- `friendbotUrl`: `<string>` (optional) - The URL of this network's "friendbot" faucet
- `passphrase`: `<string>` - Network passphrase configured
- `protocolVersion`: `<string>` - Protocol version of the latest ledger
<RpcMethod method="getNetwork"/>

## Examples

Expand Down
28 changes: 3 additions & 25 deletions api/methods/getTransaction.mdx
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
---
sidebar_position: 8
hide_title: true
---

import ExampleRequest from "@site/src/components/ExampleRequest";
import {RpcMethod} from "@site/src/components/RpcMethod";

Clients will poll this to tell when the transaction has been completed.


## Parameters

- `<hash>` - transaction hash to query, as a hex-encoded string

## Returns

- `<object>`
- `status`: `<status>` - the current status of the transaction by hash, one of:
- `SUCCESS`
- `NOT_FOUND`
- `FAILED`
- `latestLedger`: `<string>` - The latest ledger known to Soroban-RPC at the time it handled the `getTransaction()` request.
- `latestLedgerCloseTime`: `<string>` - The unix timestamp of the close time of the latest ledger known to Soroban-RPC at the time it handled the `getTransaction()` request.
- `oldestLedger`: `<string>` - The oldest ledger ingested by Soroban-RPC at the time it handled the `getTransaction()` request.
- `oldestLedgerCloseTime`: `<string>` - The unix timestamp of the close time of the oldest ledger ingested by Soroban-RPC at the time it handled the `getTransaction()` request.
- `ledger`: `<string>` - (optional) The sequence of the ledger which included the transaction. This field is only present if `status` is `SUCCESS` or `FAILED`.
- `createdAt`: `<string>` - (optional) The unix timestamp of when the transaction was included in the ledger. This field is only present if `status` is `SUCCESS` or `FAILED`.
- `applicationOrder`: `<number>` - (optional) The index of the transaction among all transactions included in the ledger. This field is only present if `status` is `SUCCESS` or `FAILED`.
- `feeBump`: `<boolean>` - (optional) Indicates whether the transaction was fee bumped. This field is only present if `status` is `SUCCESS` or `FAILED`.
- `envelopeXdr`: `<xdr.TransactionEnvelope>` - (optional) A base64 encoded string of the raw TransactionEnvelope XDR struct for this transaction.
- `resultXdr`: `<xdr.TransactionResult>` - (optional) A base64 encoded string of the raw TransactionResult XDR struct for this transaction. This field is only present if `status` is `SUCCESS` or `FAILED`.
- `resultMetaXdr`: `<xdr.TransactionResultMeta>` - (optional) A base64 encoded string of the raw TransactionResultMeta XDR struct for this transaction.
<RpcMethod method="getTransaction"/>

## Examples

Expand Down
25 changes: 3 additions & 22 deletions api/methods/sendTransaction.mdx
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
---
sidebar_position: 7
hide_title: true
---

import ExampleRequest from "@site/src/components/ExampleRequest";
import {RpcMethod} from "@site/src/components/RpcMethod";

Submit a real transaction to the Stellar network. This is the only way to make changes "on-chain".

Unlike Horizon, this does not wait for transaction completion. It simply validates and enqueues the transaction. Clients should call getTransaction to learn about transaction success/failure.

This supports all transactions, not only smart contract-related transactions.

## Parameters

- `<xdr.TransactionEnvelope>` - The signed transaction to broadcast (serialized in base64)

## Returns

- `<object>`
- `hash`: `<hash>` The transaction hash (in an hex-encoded string).
- `status`: `<status>` - The current status of the transaction by hash, one of:
- `PENDING` - The transaction has been accepted by stellar-core.
- `DUPLICATE` - The transaction has already been submitted to stellar-core.
- `TRY_AGAIN_LATER` - The transaction was not included in the previous 4 ledgers and is banned from the next few ledgers.
- `ERROR` - An error occurred from submitting the transaction to stellar-core.
- `latestLedger`: `<string>` - The latest ledger known to Soroban-RPC at the time it handled the `sendTransaction()` request.
- `latestLedgerCloseTime`: `<string>` - The unix timestamp of the close time of the latest ledger known to Soroban-RPC at the time it handled the `sendTransaction()` request.
- `errorResultXdr`: `<xdr.TransactionResult>` - (optional) If the transaction status is `ERROR`, this will be a base64 encoded string of the raw TransactionResult XDR struct containing details on why stellar-core rejected the transaction.
<RpcMethod method="sendTransaction"/>

## Examples

Expand Down
26 changes: 3 additions & 23 deletions api/methods/simulateTransaction.mdx
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
---
sidebar_position: 8
hide_title: true
---

import ExampleRequest from "@site/src/components/ExampleRequest";
import {RpcMethod} from "@site/src/components/RpcMethod";

Submit a trial contract invocation to simulate how it would be executed by the network. This endpoint calculates the effective transaction data, required authorizations, and minimal resource fee. It provides a way to test and analyze the potential outcomes of a transaction without actually submitting it to the network.

## Parameters

- `<xdr.TransactionEnvelope>` - The transaction to be simulated (serialized in base64)

## Returns

- `<object>`
- `minResourceFee`: `<string>` (optional) stringified number - Recommended minimum resource fee to add when submitting the transaction. This fee is to be added on top of the [Stellar network fee](https://developers.stellar.org/docs/encyclopedia/fees-surge-pricing-fee-strategies#network-fees-on-stellar). Not present in case of error.
- `cost`: `<object>` (optional) - Information about instructions used, etc. Not present in case of error.
- `cpuInsns`: `<string>` stringified number - Total cpu instructions consumed by this transaction
- `memBytes`: `<string>` stringified number - Total memory bytes allocated by this transaction
- `results`: `<object[]>` (optional) - This array will only have one element: the result for the Host Function invocation. Only present on successful simulation (i.e. no error) of `InvokeHostFunction` operations.
- `xdr`: `<xdr.ScVal>` serialized base64 string - return value of the Host Function call.
- `auth`: `<xdr.ContractAuth[]>` array of serialized base64 strings - Per-address authorizations recorded when simulating this Host Function call.
- `transactionData`: `<xdr.SorobanTransactionData>` (optional) serialized base64 string - The recommended Soroban Transaction Data to use when submitting the simulated transaction. This data contains the refundable fee and resource usage information such as the ledger footprint and IO access data (serialized in a base64 string). Not present in case of error.
- `events`: `<xdr.DiagnosticEvent[]>` (optional) array of serialized base64 strings - Array of the events emitted during the contract invocation. The events are ordered by their emission _time_. (an array of serialized base64 strings). Only present when simulating of `InvokeHostFunction` operations, note that it can be present on error, providing extra context about what failed.
- `restorePreamble`: `<object>` (optional) - It can only be present on successful simulation (i.e. no error) of `InvokeHostFunction` operations. If present, it indicates that the simulation detected expired ledger entries which need to be restored before the submission of the `InvokeHostFunction` operation. The `minResourceFee` and `transactionData` fields should be used to submit a transaction containing a `RestoreFootprint` operation.
- `minResourceFee`: `<string>` stringified number - Recommended minimum resource fee to add when submitting the `RestoreFootprint` operation. This fee is to be added on top of the [Stellar network fee](https://developers.stellar.org/docs/encyclopedia/fees-surge-pricing-fee-strategies#network-fees-on-stellar).
- `transactionData`: `<xdr.SorobanTransactionData>` serialized base64 string - The recommended Soroban Transaction Data to use when submitting the `RestoreFootprint` operation.
- `latestLedger`: `<string>` stringified number - Current latest closed ledger (LCL) observed by the node when this response was generated. Always present.
- `error`: `<string>` (optional) - This field will include details about why the invoke host function call failed. Only present if the transaction simulation failed.
<RpcMethod method="simulateTransaction"/>

## Examples

Expand Down
Loading