Walkthrough: Creating and Managing a Mynth Intent with Restish
Mynth is built upon the concept of intents. When a user desires to perform an action on a blockchain, instructions are embedded into an intent. The intent is encoded as proto. Proto can be considered like bytecode for the intent. The proto contains instructions for validating the execution of an intent. An intent is represented as a contract on-chain, allowing users to lock funds into the contract and for execution of the intent to be fulfilled.
Mynth supports many types of intents. Currently there are two endpoints for generating intents:
-
/api/address/generate
-
/api/address/forward
generate
is a standard cross-chain swap. forward
allows forwarding of tokens after the tokens have arrived on their destination chain; this is useful for integrating with dapps.
This guide will walk through how to generate an intent using Restish. If you haven't set up Restish yet, see our guide:
https://docs.mynth.ai/guide/restish/setting-up-restish
We'll also use mywallet
. See the README:
https://github.com/MynthAI/wallet
Step 1: Generate an Intent
To create an intent for swapping USDT on Solana to USDC on Base:
restish mynth post-api-address-generate '
price: 1.01,
source.blockchain: solana,
source.token: Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB,
target.address: 0xF296258D7c207230DeC4a57A6Adb8e57d7711aEF,
target.blockchain: base,
target.token: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
owner: 1bb175cc326a0fb334b646e3e698101da6a675e6748564dd77b5147a,
providerId: example
' -rf body.contents
-
price
is the price for the token exchange and embeds the fee. As USDT → USDC is a 1:1 swap, the base value is one; aprice
of 1.01 means the fee will be 1%. For example, if 100 USDT is sent, then 99 USDC will be received. -
providerId
can be set to your unique dapp ID. Each swap associated with thisproviderId
will be credited the fee for the swap. Currently, to register for fee claims, you must speak with the Mynth team; later on it will be open access to everyone. -
owner
is the authority who can cancel the intent if it expires without execution. It is the BLAKE2b-224 hash of the Ed25519 public key, whose private key can be used to sign the intent hash. Themywallet
CLI provides some helper commands to make this easier.
To see your address:
mywallet addresses
public: 1bb175cc326a0fb334b646e3e698101da6a675e6748564dd77b5147a
Use this for the owner
field so that you can use mywallet
to cancel the intent.
Step 2: Intent Output
This will produce something like:
{
address: "9yoDr3Uhe2BDPTcj946HFaTyQf6dgtFar8upaVnVpniA",
binary: "CkA5Y2YyMzYxMGMxNzAxMzU5NjkyNjI1ZWJiNTVkMGI4MWI4ZTc4MDRlY2Q4ODY4ZGJjMWU4ZjVhMDZlMDI2YjYwEgZzb2xhbmEaBGJhc2UiKjB4RjI5NjI1OEQ3YzIwNzIzMERlQzRhNTdBNkFkYjhlNTdkNzcxMWFFRio4NDIwNGE2MTdiMGRhNWE2Y2I3MGM1Y2E5ODY1ZjVhMjg4YzZhMmEyZmZlYjk4ZDAzZTI3OTc0OTYyODQyMDRhNjE3YjBkYTVhNmNiNzBjNWNhOTg2NWY1YTI4OGM2YTJhMmZmZWI5OGQwM2UyNzk3NDk2OioweDgzMzU4OWZDRDZlRGI2RTA4ZjRjN0MzMkQ0ZjcxYjU0YmRBMDI5MTNCLEVzOXZNRnJ6YUNFUm1KZnJGNEgyRllENEtDb05rWTExTWNDZThCZW53TllCSGVQZFjooMbDBmDYhMbDBmoHZXhhbXBsZQ==",
hash: "70d9bfb87721f5e3b87e78cfc9e901e251d3bfb20ea50a93468c2dbc591e2cd1",
message: "This is an intent to swap Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB on solana for 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 on Base at a price of 1.01. This intent expires in an hour."
}
-
address
is the contract the user can send funds to. The contract will be unlockable when either the intent expires, or the intent is validated as completed. -
binary
is the intent proto. This should be referenced if the user later wishes to cancel the intent after expiration. -
hash
is the BLAKE3 hash of the intent proto, and can be used for tracking purposes.
Step 3: Track the Intent
To track the intent:
restish mynth get-api-address-track --hash 70d9bfb87721f5e3b87e78cfc9e901e251d3bfb20ea50a93468c2dbc591e2cd1 -rf body.contents
{
address: "9yoDr3Uhe2BDPTcj946HFaTyQf6dgtFar8upaVnVpniA",
amount: "0",
confirmed: false,
detected: false,
english: "This is an intent to swap Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB on solana for 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 on Base at a price of 1.01. This intent expires in an hour.",
expired: false,
finished: false,
hash: "70d9bfb87721f5e3b87e78cfc9e901e251d3bfb20ea50a93468c2dbc591e2cd1",
intent: "CkA5Y2YyMzYxMGMxNzAxMzU5NjkyNjI1ZWJiNTVkMGI4MWI4ZTc4MDRlY2Q4ODY4ZGJjMWU4ZjVhMDZlMDI2YjYw...",
sent: false,
status: "waiting"
}
We can see that the status is currently waiting
. After the user sends funds into the contract, the status will update and the intent will be fulfilled.
Step 4: Cancel the Intent (if needed)
After waiting an hour without any action, the intent can be canceled via the /api/address/cancel
endpoint. First, the intent proto needs to be signed.
Use mywallet
to sign the intent:
mywallet payload sign CkA5Y2YyMzYxMGMxNzAxMzU5NjkyNjI1ZWJiNTVkMGI4MWI4ZTc4MDRlY2Q4ODY4ZGJjMWU4ZjVhMDZlMDI2YjYwEgZzb2xhbmEaBGJhc2UiKjB4RjI5NjI1OEQ3YzIwNzIzMERlQzRhNTdBNkFkYjhlNTdkNzcxMWFFRio4NDIwNGE2MTdiMGRhNWE2Y2I3MGM1Y2E5ODY1ZjVhMjg4YzZhMmEyZmZlYjk4ZDAzZTI3OTc0OTYyODQyMDRhNjE3YjBkYTVhNmNiNzBjNWNhOTg2NWY1YTI4OGM2YTJhMmZmZWI5OGQwM2UyNzk3NDk2OioweDgzMzU4OWZDRDZlRGI2RTA4ZjRjN0MzMkQ0ZjcxYjU0YmRBMDI5MTNCLEVzOXZNRnJ6YUNFUm1KZnJGNEgyRllENEtDb05rWTExTWNDZThCZW53TllCSGVQZFjooMbDBmDYhMbDBmoHZXhhbXBsZQ==
This will output the signature.
Now cancel the intent:
restish mynth post-api-address-cancel '
intent: CkA5Y2YyMzYxMGMxNzAxMzU5NjkyNjI1ZWJiNTVkMGI4MWI4ZTc4MDRlY2Q4ODY4ZGJjMWU4ZjVhMDZlMDI2YjYwEgZzb2xhbmEaBGJhc2UiKjB4RjI5NjI1OEQ3YzIwNzIzMERlQzRhNTdBNkFkYjhlNTdkNzcxMWFFRio4NDIwNGE2MTdiMGRhNWE2Y2I3MGM1Y2E5ODY1ZjVhMjg4YzZhMmEyZmZlYjk4ZDAzZTI3OTc0OTYyODQyMDRhNjE3YjBkYTVhNmNiNzBjNWNhOTg2NWY1YTI4OGM2YTJhMmZmZWI5OGQwM2UyNzk3NDk2OioweDgzMzU4OWZDRDZlRGI2RTA4ZjRjN0MzMkQ0ZjcxYjU0YmRBMDI5MTNCLEVzOXZNRnJ6YUNFUm1KZnJGNEgyRllENEtDb05rWTExTWNDZThCZW53TllCSGVQZFjooMbDBmDYhMbDBmoHZXhhbXBsZQ==,
signature: 011bb175cc326a0fb334b646e3e698101da6a675e6748564dd77b5147afefd4435029bb3b2c49e971e30fc8eccf6a9388e3a6b02eef52b020aa4010103272006215820a1e3d9c6281256390dccd71aa44587de6e0b5c7de06b8171ec01600c8f166fb9845846a2012767616464726573735839011bb175cc326a0fb334b646e3e698101da6a675e6748564dd77b5147afefd4435029bb3b2c49e971e30fc8eccf6a9388e3a6b02eef52b020aa166686173686564f4582070d9bfb87721f5e3b87e78cfc9e901e251d3bfb20ea50a93468c2dbc591e2cd15840870e39bbc8f7150363e63d63db3cdc621c3128c3cf2cdec8d863f3b13dbe3c21fc9654ecdf5280c83c0e7eb712b9505fcec46703ace8a0ff263fa8c2d01c090c
' -rf body.contents.seed
This will return back the seed for the contract, so that funds can be withdrawn.
You can use mywallet restore
to load the seed, and then verify the address using:
mywallet addresses
This will output the same Solana address as the original call to /api/address/generate
.