Blog: New JSON RPC Libra Client-API

We’ve made two changes to the Libra client API. The API will now be based on JSON-RPC, and proof verification has been removed to a separate API. Read this blog to learn why these changes were made and the advantages of this new approach. https://libra.org/en-US/blog/new-json-rpc/

If you have comments on the blog, we invite you to reply to this topic.

3 Likes

I am wondering if rust had support for grpc-gateway (https://github.com/grpc-ecosystem/grpc-gateway) would this have changed your decision?

Using the grpc made sense with the earlier assumption that Libra could use the grpc serialization and sign transactions serialized with it. But when it turned out it actually cannot be used for this and Libra Canonical Serialization was developed, it was nigthmare to use the api: putting some information in structures generated from grpc protos and serializing some things with the LCS + similar work with de-serialization.

I think this new json-rpc api is also more developer friendly as you can create the api requests with tools like curl and postman. The integration is also more transparent when there isn’t the grpc library in between doing it’s magic and you can choose what ever http client available for your platform.

The only downside is the LCS serialization which needs to be implemented by the library doing the integration (at least if creating transactions is a requirement, all the queries can be done without it).

1 Like

Where is the document of the new json-rpc client API?

It’s here https://github.com/libra/libra/blob/master/json-rpc/json-rpc-spec.md but looks like it has not been updated with latest changes (the Account response does not have the support for multiple currencies).

Also the libra command line client uses this api, so you’ll be able to find examples there.
The address of the api is http://client.testnet.libra.org/

1 Like

Thanks for all the great comments. The missing link in the blog has been restored, and you will find the API docs here: https://github.com/libra/libra/blob/master/json-rpc/json-rpc-spec.md

Where is the new separate API doc for proof verification?

1 Like

The updated API docs are here: https://github.com/libra/libra/blob/master/json-rpc/json-rpc-spec.md

Where is the doc for the separated proof verification APIs?

There are no documentation for it yet, but you can see how it is being used in here:

Hi,

For submit method, it require a parameter of type

Signed transaction data

How to generate it?

Currently, you could use this CLI tool to do it: https://github.com/libra/libra/blob/master/client/swiss-knife/src/main.rs#L68

we are still working on a couple of cross-language way of doing it.

I’m trying to create simple wallet app using the API,

I can’t find how to get all transaction for account address, both send or received.

I checked it up in GitHub documentation
https://github.com/libra/libra/blob/master/json-rpc/json-rpc-spec.md

get_transactions: can’t filter by account address
get_account_transaction: return only one sent transaction (no received transactions)

Anyone can help?

for now the logic for you would be:

1.  call "get_account" to get latest account sequence number
2. for i in range(0, seq-1):
           call "get_account_transaction" with (account, i) , to get transaction for that seq. 
     done

this logic will allow you to get all transaction sent by this account , note that there are no such thing as “received” transaction for an account, you can only get transactions that was sent by this account.

Yes, supporting this in an single JSONRPC method call is an missing function to be implemented in the json rpc, if you feel strongly about it, please file an issue on github and assign it to me.

You can also utilize the JSON-RPC batch request to get all the transactions in one request.

If you need to get information about the transactions that have sent money to an account, you can use the get_events method of the RPC api. You need to provide an “event key” as a parameter and the event keys can be found in the response of the get_account method.

Is there any where i can confirm the docs for faucet.testnet.libra.org ? I having been getting 500 INTERNAL SERVER ERROR

My request parameters

POST amount=10000000&auth_key=xxxxxxxxx&currency_code=LBR

yes it is correct, faucet sometime doesn’t handle concurrent request well, so make sure to not send too fast

Thank you for your replay and for the get_account_transactions method, I’m waiting it to be published on testnet.

Also, I got an error from JSON-RPC API submit when using swiss-knife generated signed transaction saying:

-32000 Server error: remaining input

When comparing swiss-knife output with json-rpc submit documentation examples,
The swiss-knife output ( signed_txn + txn_hash) is less by 4 char

What am I missing? is there additional parameter should be appended?

make sure your uses the “testnet” branch of swiss-knife.

-32000 errors are deserialization errors , usually because you are using an old or new version of tooling

Hi ,
I am having gas price error in my transaction , I have increase and decrease it , still the same error.

-32010: Server error: Mempool submission error: "Failed to update gas price to 3