In this section we cover how to use Action Chaining to create multi-step experiences with blinks. Our github has multiple action chaining examples, includingDocumentation Index
Fetch the complete documentation index at: https://docs.dialect.to/llms.txt
Use this file to discover all available pages before exploring further.
- Swapping back and forth between tokens
- Inline chaining
- Action chaining with no transaction
- External links
Example: Swapping back and forth between tokens
In this example we create a blink that swaps from SOL to BONK in the first step, and then from BONK back to SOL in the second.
The first action, app.get('SOL-BONK', async (c) => { ... } (link) returns an an input field (a linked parameterized action) for the user to specify the amount to swap. This is no different than a non-chained actions response.
On submit, a POST call is made to app.post('SOL-BONK/:amount', async (c) => { ... } (link). This response includes both the transaction data as expected, but now also the links attribute with a next attribute in it. This next attribute powers action chaining.
response.links.next.href URL is the relative path to the next action, and type: 'post' indicating that chaining is done through a POST request to the specified href. The alternative chaining method, type: 'inline', will be explained in the next section.
Once the user signs and the transaction succeeds, the client directs the blink to the next action in the chain, in this case app.post(/BONK-SOL', async (c) => { ... } (link), which returns metadata to render the second action in the chain.
app.post('/BONK-SOL/:amount', async (c) => { ... } (link) which then returns the transaction to sign and submit to the blockchain.
See the full code here, or browse other action chaining examples here.
Inline chaining
When using inline chaining, instead of returning alinks.next.href string for the URL to call in the next step that would return an Action object, that Action object is returned directly in links.next.action.