Smart Deploy API / Mercury Client in Rust
This repository contains a Mercury client developped in Rust with Shuttle. It uses the crates axum, reqwest and graphql-client.
More precisely, it requests specific data indexed by Mercury in order to diplay it in the SmartDeploy Dapp. Below is the architecture of the whole system:
Mercury is an indexer service for Stellar and Soroban blockchain. Check more in the Mercury Docs Page.
- You need a Mercury Token access to use the service. See Request Access.
- You must have already subscribed to contract events or ledger entries. To understand the purpose of subscriptions, check out that section.
Struggling to subscribe to contract event or ledger entries? Check out our Javascript implementation. - Install shuttle:
$ cargo install cargo-shuttle
- Set up your
Secrets.toml
file as following:
MY_JWT_TOKEN = 'your-mercury-jwt-token'
MERCURY_GRAPHQL_ENDPOINT = 'http://ec2-16-170-242-7.eu-north-1.compute.amazonaws.com:5000'
Of course, you will add your Mercury Access Token provided by the team.
- If you want to query an event by its topic, you have to know the base64-encoded XDR of that topic and paste it in your GraphQL query (see
queries/query_deploy.graphql
).
As an example, if your event topic issymbol_short!("deploy")
, you can have its corresponding XDR by running in a node environment:
const sorobanClient = require('soroban-client');
const myTopic = sorobanClient.xdr.ScVal.scvSymbol("deploy").toXDR("base64");
console.log(myTopic);
-
Define a route to trigger the GraphQL request. In our example, the route is "/get_deploy" and the corresponding handler is the function
get_deploy_event
(seesrc/main.rs
). -
Test locally whether everything is working properly:
$ cargo shuttle run
# or if you want to see the logs
$ RUST_LOG=debug cargo shuttle run
Then, start the http request by accessing http://127.0.0.1:8000/get_deploy
.
- Deploy your application on Shuttle servers
$ cargo shuttle deploy
- Decode the XDR data returned by the Indexer and return that decoded data to the Dapp
- Add a mutation to renew the Mercury API Token?