Skip to main content

Handle operation dependencies using intents

In this guide, you will learn how to manage operation dependencies using intents with the MARCO API.

Every MARCO operation is labeled with an intent, a unique identifier that ensures operations occur in the correct order and only after certain conditions are met.

Scenario

Imagine you want to implement an app to send funds to a vendor. However, before the funds transfer, you want to wait until a validation operation confirms the recipient's identity and checks the sender's balance.

In this case, you can use intents to ensure these operations execute in the correct order. The validation operation is sent with a specific intent, and the funds transfer operation is dependent on that intent. If the validation is successful, the funds transfer proceeds.

Here's how the intents and their dependencies are connected in this scenario:

graph LR; A(Intent A) -->|Success| B(Intent B)
  • Intent A (Validation operation): Does not have any dependencies.
  • Intent B (Transfer operation): Depends on Intent A.

Prerequisites

Before you start, complete the following prerequisites:

1. Send the validation transaction

Use the Send Operation endpoint to send the validation transaction with intent A:

    --data '{
"dependencies": [],
"intent": "<INTENT_UUID_A>",
...
}'

Replace the placeholder <INTENT_UUID> and the call with your actual values.

tip

If you need to generate UUIDs for testing purposes, you can use an online tool such as UUID generator.

2. Send the transfer transaction

Now, use the Send Operation endpoint to send the funds with a dependency on intent A:

    --data '{
"dependencies": ["<INTENT_UUID_A>"],
"intent": "<INTENT_UUID_B>",
...
}'

This ensures the transfer operation executes after the validation operation succeeds.

3. Handle validation errors

If the validation operation gets rejected, you can resend it with the same intent. The fund transfer (intent B) will wait for a successful validation operation (intent A).

    --data '{
"dependencies": [],
"intent": "<INTENT_UUID_A>",
...
}'

Next step

You've learned to use intents to manage operation dependencies. In this scenario, the transfer operation waits for the validation operation successful completion, ensuring operations execute in the correct sequence.

Now, you can adapt and expand this process according to your specific transaction dependency requirements.