Craft Transaction without SDK
Create Swap Intent
Building a swap intent is straightforward - you just need to create a transaction output at the swap intent script address, locking fromAmount + deposit with a valid SwapIntentDatum.
Mainnet
addr1zyjg3n7aut48cgfy8s974uc79sfm985jvlend7nng9cq5ekll0mlqdcg2cee0s4ea9vaa9u79xmftptm8akvk55yslks48uca3
Preprod
addr_test1zrulf7dqhh92neevg7rlx64029fqy3yk750pwwqrc9hvdwkll0mlqdcg2cee0s4ea9vaa9u79xmftptm8akvk55yslksh40p2w
Minimum Order Value: Order value must be at least 10 USDM / USDCx equivalent.
SwapIntentDatum Structure
// Aiken
pub type SwapIntentDatum {
account_address: Address, // User's address to receive output tokens
from_amount: MValue, // Assets user is selling
to_amount: MValue, // Minimum assets user expects to receive
created_at: Int, // Slot number (used for cancellation timing)
deposit: Lovelace, // Min UTxO deposit in lovelace (typically 2000000)
}
pub type MValue = Pairs<PolicyId, Pairs<AssetName, Int>>// Type definition (imported from @meshsdk/core)
type SwapIntentDatum = ConStr0<
[
PubKeyAddress | ScriptAddress, // account_address
Pairs<PolicyId, Pairs<AssetName, Integer>>, // from_amount (MValue)
Pairs<PolicyId, Pairs<AssetName, Integer>>, // to_amount (MValue)
Integer, // created_at (slot)
Lovelace, // deposit
]
>;
// Constructor function that builds a SwapIntentDatum for on-chain storage
const datum = swapIntentDatum({
accountAddress: "addr_test1...",
fromAmount: [{ unit: config.tokens.night, quantity: "100000000" }],
toAmount: [{ unit: config.tokens.usdm, quantity: "5000000" }],
createdAt: 12345678,
deposit: 2000000, // optional, default 2 ADA
});The transaction must
Create output at swap intent script address with:
Value:
fromAmount + depositInline datum:
SwapIntentDatum
Example Datum
SELL 50 ADA for 12.5 USDCx
BUY 60 ADA with 15 USDCx
Cancel Swap Intent
Cancellation is only allowed after the intent expires (~10 minutes from createdAt).
Cancellation Timing: Users can only cancel their swap intent 10+ minutes after creation.
CancelIntent Redeemer
The transaction must
Reference the oracle UTxO (read-only)
Spend the swap intent UTxO with redeemer
CancelIntentSet
invalidBeforetocreatedAt + 600slot (~10 minutes)Either
Must set
extra_signatorieswithaccountAddress's payment key hash, ORInput value sent back to
accountAddress
Last updated