If you're here to add a new method to one of the specfiles, you'll want to:
-
Create a new
<method_name>.jsonfile in the relevant/openrpc/src/{stellar-rpc,anchor-platform}/methodsdirectory. Follow the OpenRPC specification concerning method objects for defining this file. -
Feel free to use any existing (or create new)
$refobjects along the way. More about them later on. -
Once your method is defined the way you want it, run the build and validate scripts to generate updated "bundled" specfiles.
-
Run
pnpm rpcspec:docsto generate the method's page. Method pages are MDX generated from the bundled specfile (between{/* rpc-method ... */}and{/* /rpc-method */}comments), with any hand-written prose before or after the generated part. The script rewrites only the generated part, and creates a page for a new method. A new page also needs an entry indocs.jsonnavigation and a card on the methods index page; the script prints a reminder. Method pages live in:- For stellar-rpc:
/docs/data/apis/rpc/api-reference/methods - For anchor-platform:
/docs/platforms/anchor-platform/api-reference/platform/rpc/methods
- For stellar-rpc:
Methods that only the archive RPC node serves, and that can still change, go in
/openrpc/src/stellar-rpc-beta/ instead of /openrpc/src/stellar-rpc/. They
build into a separate /stellar-rpc-beta.openrpc.json, so the main spec that
third parties consume stays unchanged. The beta service reuses every component
(schemas, content descriptors, examples) of stellar-rpc, so a beta method can
$ref things like #/components/schemas/Event directly. A beta method's page
is generated from the beta spec, and keeps a hand-written beta <Warning> above
the generated part.
When a beta method ships in a general RPC release:
- Move its files from
/openrpc/src/stellar-rpc-beta/into the matching directories under/openrpc/src/stellar-rpc/. Merge or replace any beta-local override that shares a name with a main spec component. - Regenerate the method's page from the main spec.
- Remove the beta
<Warning>from the page and any beta mentions that link to it. - Remove the
stellar-rpc-betaservice fromscripts/build.mjsandscripts/validate.mjsif no beta method remains.
These are specifications of the APIs presented by Stellar RPC and the Platform Server component of the Anchor Platform.
Note: The build process writes
/stellar-rpc.openrpc.json,/stellar-rpc-beta.openrpc.json, and/docs/platforms/anchor-platform/api-reference/platform/rpc/anchor-platform.openrpc.json. Commit these files along with your source changes: nothing rebuilds them at deploy time, and the site serves the committed copies (for example athttps://developers.stellar.org/stellar-rpc.openrpc.json). Always change the source JSON files too, not just the built files, or the next build overwrites your edit.
The specification is split into multiple files to improve readability. The complete spec can be compiled into a single document as follows. (Run this command from the root of this repository.)
pnpm rpcspec:build
# Build successful.This will output the files listed in the note above. These files will have all
schema $refs resolved.
We have included a script which will test and validate the generated specification file.
pnpm rpcspec:validate
# OpenRPC spec validated successfully.openrpc/scripts/docs.mjs renders each method in the built specfiles into its
page, replacing only the part between the rpc-method comments.
pnpm rpcspec:docs # regenerate the method pages
pnpm rpcspec:docs --check # list out-of-date pages, without writing themCI runs pnpm rpcspec:check, which rebuilds the specfiles and fails if the
committed specfiles or method pages differ from what the sources produce.
These files make extensive use of $ref objects for improved readability and
maintainability. In the separate files, the references don't mean much, but when
things are generated they'll be resolved. If you are going to reference
something in the specification, you will need to use the following format:
#/components/{schemas,examples,etc.}/NameOfComponentToReference.
The items broken out into objects that will be referenced are not held
individually in their own files. Instead, they are grouped into similar and
related files. For example: /src/examples/Transactions.json holds several
example components that are related to transactions, such as transaction
hashes, results from the getTransaction or sendTransaction methods,
transactions parameters that were sent using the sendTransaction method, etc.
Don't making any changes to *.openrpc.json or *.refs-openrpc.json! Any
changes you make there, will not be reflected in the generated specification
files. Instead, any changes should be made in the files contained in the
/openrpc/src/{stellar-rpc,anchor-platform} directories.
These directories follow a structure similar to the schema defined in the OpenRPC specification. Here are the pieces you'll need to know about:
This collection of JSON files define the method objects that will go into the generated specification file. The methods can be considered the container that will ultimately hold all of the details about how the method works (parameter types, return types, examples, etc.). The following properties are required in the method object:
name(string) - The canonical name for the method. The name MUST be unique within the methods arrayparams(list) - A list of parameters that are applicable for this method
This collection of JSON files define the contentDescriptor objects that will
go into the generated specification file. A content descriptor is a reusable way
of describing either parameters or results. (Though, I've found they're best
used as items in a method's params list). The following property are required
in the content descriptor object:
name(string) - Name of the content that is being described. If this object is defining a parameter, thenamefield will define the parameter's keyschema(object) - A schema that describes the content
This collection of JSON files define the schema objects that will go into the generated specification file. These schemas allow us to define input and output data types. These schemas MUST follow the JSON Schema Specification 7
This collection of JSON files define the example objects that will go into the
generated specification file. These objects define an example that is consistent
and matches the schema of a given content descriptor. These example objects
can act as either a parameter or result. The value property of the example
object allows us to embed a literal example of what the schema can look like.
This collection of JSON files define the example pairing objects that will go
into the generated specification file. The example pairing objects make up a
complete example request to the Stellar RPC service. This is where you can
specify a set of params that were supplied in the request, as well as the
value(s) returned in the result from the node. The following properties are
required in the example pairing objects:
name(string) - Name for the example pairingparams(list) - A list of example parameters (or$refs to example objects)result(example object) - Example result received from the node
Note: The
resultproperty is not technically required by the open-rpc specification if the method is to be represented as a notification. However, Stellar RPC doesn't make use of any methods as notifications, so we've listed it as required here.