Skip to content

Here lies RPC requests made from postman to a Soroban-RPC endpoint

License

Notifications You must be signed in to change notification settings

ElliotFriend/soroban-rpc-postman

Repository files navigation

soroban-rpc-postman

Here lies RPC requests made from postman to a Soroban-RPC endpoint

Run in Postman

Table of Contents

Note: Items listed as a work-in-progress (WIP) reflects, as far as my understanding goes, the current state of the Soroban-RPC methods that are available and working.

What's the Point Here?

Here's what you'll find in this repository:

  • A collection of the (current) JSON RPC requests that can be made against a Soroban-RPC endpoint
  • Information on how to format the requests to a Soroban-RPC endpoint
  • A collection of Postman requests that will get you going toward making those RPC requests
  • A place to get started writing scripts and apps in Python and JavaScript (because those are the main languages I know.)

Relevant Documentation

Here is some of the resources I've used in creating this collection.

The Postman Collection

You can get to a running (I think) version of the collection right in your browser by clicking the button below.

Run in Postman

Alternatively, the Soroban-RPC Requests.postman-collection.json file has the same requests in a format you could import directly into your own instance of Postman.

The Requests

The basic structure of a JSON-RPC request looks something like this:

{
    "jsonrpc": "2.0", // Specifies the JSON-RPC protocol version to use. Must be exactly "2.0"
    "id": 8675309, // An identifier for the client. I'm not entirely sure if this is required by Soroban-RPC
    "method": "<method-name>", // The name of the method to be invoked
    "params": {
        // A structured value that holds the parameter(s) being used during the invocation
        "<key>": "<value>"
    }
}

With that out of the way, here's how we use the (currently) existing methods for Soroban-RPC endpoints.

With the first method, getAccount request, I will also provide a python and javascript snippet for making the request to the endpoint. I trust you'll be able to extrapolate how to request different methods when necessary. (I will attempt to keep a working, more-complete, and up-to-date rpc_calls.py file in this repository, as well.)

getAccount

When invoking getAccount, you must supply the account's public key as the address parameter.

The response is intended to be a minimal set of account information, and will include the account ID, sequence number, and balances (not yet?).

getAccount Request

Request body:

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "getAccount",
    "params": {
        "address": "GBTXODHDMG3CHYLLTNXMUSSI7WXIAHBQTLKNCSGWGCWO3XV3MTJ7PNZA"
    }
}

getAccount Response

Response body:

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "result": {
        "id": "GBTXODHDMG3CHYLLTNXMUSSI7WXIAHBQTLKNCSGWGCWO3XV3MTJ7PNZA",
        "sequence": "3435501390397448"
    }
}

getHealth

When invoking getHealth, you are checking on the general well-being of the node. No parameters are required, nor are they accepted.

Based on my (admittedly limited) understanding of the Soroban-RPC codebase, it appears (at the moment) any getHealth request will simply return "healthy." It's unclear what ultimately will be the measure of health, or when it will be implemented.

getHealth Request

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "getHealth"
}

getHealth Response

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "result": {
        "status": "healthy"
    }
}

getLatestLedger (WIP)

When invoking getLatestLedger, you will find out the current latest known ledger of this node. This is a subset of ledger info available through Horizon.

getLatestLedger Request

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "getLatestLedger"
}

getLatestLedger Response

"work-in-progress"

According to the design-doc, it should return something like this (someday?):

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "result": {
        "id": "<hash>", // hash of the latest ledger
        "protocolVersion": "<number>",
        "sequence": "<number>"
    }
}

getLedgerEntry

Invoking getLedgerEntry is useful for reading the current value of CONTRACT_DATA ledger entries directly through RPC. This allows you to directly inspect the current state of a contract.

getLedgerEntry Request

The tricky part for this method is getting a useable value for the xdr.LedgerKey parameter. The contract below is a deployed copy of the increment example from the Soroban documentation examples. As such, the LedgerKey we need to provide is an xdr-encoded LedgerKeyContractData object made with the contractId and the ScVal representing the key.

This can be achieved using the soroban branch of the python stellar_sdk. A starter script is supplied in sc_val.py

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "getLedgerEntry",
    "params": {
        "key": "pimawTd4so6Re0r2HRYHQJK1oU6Sx+k1HYJRAOQYd+cAAAAFAAAAB0NPVU5URVIA"
    }
}

getLedgerEntry Response

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "result":  {
        "xdr": "<xdr-encoded-string>",
        "lastModifiedLedger": "1166180",
        "latestLedger": "1166323"
    }
}

getContractData

WARNING: getContractData WILL SOON BE DEPRECATED IN FAVOR OR getLedgerEntry

Invoking getContractData is useful for reading the current value of CONTRACT_DATA ledger entries directly through RPC. This allows you to directly inspect the current state of a contract.

getContractData Request

The tricky part for this method is getting a useable value for the key parameter. The contract below is a deployed copy of the increment example from the Soroban documentation examples. As such, the key we need to provide is an xdr-encoded ScVal of the symbol COUNTER.

This can be achieved using the soroban branch of the python stellar_sdk. A starter script is supplied in sc_val.py

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "getContractData",
    "params": {
        "contractId": "a6299ac13778b28e917b4af61d16074092b5a14e92c7e9351d825100e41877e7",
        "key": "AAAABQAAAAdDT1VOVEVSAA=="
    }
}

This method can also be used to retrieve WASM byte-code that is stored on the ledger. This requires us to supply a key of the ContractCode SCVal ledger entry. Here's what the request would look like:

"something"

getContractData Response

For the first request above (the "COUNTER" data entry). The returned xdr can be decoded as in sc_val.py:

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "result": {
        "xdr": "AAAAAQAAAAQ=",
        "lastModifiedLedgerSeq": "1166180",
        "latestLedger": "1166323"
    }
}

The response with the WASM byte-code looks like this:

"something

getEvents

The getEvents method can be used for a client to retrieve a filtered list of events that are emitted by a specified ledger range.

getEvents Request

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "getEvents",
    "params": {
        "startLedger": "100",
        "endLedger": "1000",
        "filters": {
            "type": "contract",
            "contractIds": [
                "a6299ac13778b28e917b4af61d16074092b5a14e92c7e9351d825100e41877e7",
                "4018b6f8f2d50449d001920362be249d2bdf768d5a6da6ce73146a994d8747c7"
            ],
            "topics": [
                // "AAAABQAAAAh0cmFuc2Zlcg==" === ScSymbol("transfer").toXdr().toString('base64')
                // Matches any token transfer events
                ["AAAABQAAAAh0cmFuc2Zlcg==", "*", "*"],
                // Matches any token transfer events to recipient: `GABC...123`
                ["AAAABQAAAAh0cmFuc2Zlcg==", "*", "GABC...123"],
                // Matches only token transfers from `GDEF...456` to `GABC...123`
                ["AAAABQAAAAh0cmFuc2Zlcg==", "GDEF...456", "GABC...123"],
            ]
        },
        "pagination": {
            "cursor": "1234-1",
            "limit": 100
        }
    }
}

getEvents Response

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "result": {
        "events": {
            "ledger": "<string>", // string-ified sequence number of the ledger
            "ledgerClosedAt": "<string>", // ISO8601 timestamp of the ledger closing time
            "contractId": "<string>", // id of the emitting contract
            "id": "<string>", // event's unique id
            "pagingToken": "<string>", // same as `id` field, but expected here for paging
            "topic": "<xdr.ScVal[]>", // list of topics this event was emitted with
            "value": {
                "xdr": "<xdr.ScVal>" // the body of the event (base64-encoded string)
            }
        }
    }
}

getNetwork (WIP)

The getNetwork method returns general information about the currently configured network.

getNetwork Request

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "getNetwork"
}

getNetwork Response

"work-in-progress"

getTransactionStatus

You can use getTransactionStatus to find out if a sent transaction has been successful, failed, etc. You will also get a results response with anything that was returned by the transaction. In the example below, the transaction was deploying the increment contract, and the results contains the bytes of the contract ID.

getTransactionStatus Request

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "getTransactionStatus",
    "params": {
        "hash": "9975a8f097fe3e6a3c6048a5c91631202b8f4f2b5f6edb2f81655631aeb3ef51"
    }
}

getTransactionStatus Response

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "result": {
        "id": "9975a8f097fe3e6a3c6048a5c91631202b8f4f2b5f6edb2f81655631aeb3ef51",
        "status": "success",
        "results": [
            {
                "xdr": "AAAABAAAAAEAAAAEAAAAIKYpmsE3eLKOkXtK9h0WB0CStaFOksfpNR2CUQDkGHfn"
            }
        ]
    }
}

requestAirdrop (WIP)

The requestAirdrop is a friendbot interface. A request can be made (outside of the public network) to give lumens to a particular account.

requestAirdrop Request

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "requestAirdrop",
    "params": {
        "account": "GD3LWOYS4I6P2VF43MH2E627O5LMIJWCSGNIP3Y7SNWU52FGJT4ZI7VP"
    }
}

requestAirdrop Response

"work-in-progress"

sendTransaction

The sendTransaction allows you to submit a real stellar transaction. You don't get a status in return, you are expected to use getTransactionStatus to find out if it was successful or not, and to get any return from the invocation.

sendTransaction Request

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "sendTransaction",
    "params": {
        "transaction": "AAAAAgAAAABndwzjYbYj4WubbspKSP2ugBwwmtTRSNYwrO3eu2TT9wAAAGQAEcpoAAAABgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACgAAAAVoZWxsbwAAAAAAAAEAAAAHc29yb2JhbgAAAAAAAAAAAbtk0/cAAABA7S8ZDIj5I/NrZKIEtU9DDF/XNiUlKslxuCkQxUnpz++9+yZ2DdbrCI8yO+CP/BP+hKr5gxfBxJQMdDuAW5LHBw=="
    }
}

sendTransaction Response

"something"

simulateTransaction

The simulateTransaction method is intended to submit a trial invocation of a smart contract to get back return values, ledger footprint, expected costs, etc. I don't seem to be able to make this work. That might be because I'm trying to use a "classic" stellar transaction?

simulateTransaction Request

{
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "simulateTransaction",
    "params": {
        "transaction": "AAAAAgAAAABndwzjYbYj4WubbspKSP2ugBwwmtTRSNYwrO3eu2TT9wAAAGQAEcpoAAAABgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACgAAAAVoZWxsbwAAAAAAAAEAAAAHc29yb2JhbgAAAAAAAAAAAbtk0/cAAABA7S8ZDIj5I/NrZKIEtU9DDF/XNiUlKslxuCkQxUnpz++9+yZ2DdbrCI8yO+CP/BP+hKr5gxfBxJQMdDuAW5LHBw=="
    }
}

simulateTransaction Response

"work-in-progress"

About

Here lies RPC requests made from postman to a Soroban-RPC endpoint

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published