The OPTIONS and POST Request

To close out, we'll discuss how OPTIONS and POST requests work.

OPTIONS request

As with the other requests we've seen, the OPTIONS request requires CORS headers. This is pretty straightforward:

export const OPTIONS = GET;

POST request

Users then execute an Action through a POST request sent to either the Action URL itself or one of the linked Action URLs.

The body of the POST request contains the wallet address that connects to the client unfurling the Action and can be derived using the following line of code:

export const POST = async (req: Request) => {
  const body: ActionPostRequest = await req.json(); 
    
  // insert transaction logic here    
      
  const payload: ActionPostResponse = await createPostResponse({
    fields: {
      transaction,
      message: "Optional message to include with transaction",
    },
  });
  
  return Response.json(payload, {
    headers,
  });
};

When a POST request is submitted to the Action API endpoint, a transaction (with an optional message) is returned through the payload, and it has to be signed by the user. For the full scope of the POST request and response, check out the full POST specifications.

Actions support a wide variety of transactions--anything that the Solana blockchain can execute. The most common libraries used for the transaction logic are @solana/web3.js and @metaplex-foundation/umi.

Full responsibility for signing and submitting the transaction belongs to the client, but the Dialect Blinks SDK manages the UI unfurling and execution lifecycle of the Action.

Conclusion

There you have it, everything you need to get up and running with Actions! For more examples on building Actions, check out the various open-source examples on our Github, which include code for various important ecosystem partners like Helius, Jupiter, Meteora, Sanctum and Tensor.

Last updated