Integrating Mach

More integration examples are coming! Feel free to ping us on Telegram and we will work with you directly to fast track your integration.

Integrating Mach into Client Apps

Fundamentally, there are three steps:

  1. Load the token contract addresses that the user wants to transact between & the swap Mach contract on the sell-side network (and make sure that token spend is approved). You can get all of our supported tokens and networks here

  2. Build and issue a transaction that execute the placeTrade function on the Mach contract, which places an order onto the order book

  3. Build and issue an API call to a backend server that fills the order (check out ours in our API doc here)

/** Step 1 **/
// Check and approve the sell-side token spend on Arbitrum
await checkAndApproveAllowance(wallet);

// Load the Mach contract on Arbitrum
const swapContract = getSwapContract(wallet);


/** Step 2 **/
// Build smart contract transaction function arguments
const transactionFunctionArgs = getTransactionFunctionArgs();

// Execute the token exchange by issuing smart contract transaction
const tx = await swapContract["placeTrade"](...transactionFunctionArgs);
const receipt = await tx.wait();


/** Step 3 **/
// Fetch the event log for the OrderPlaced events
const event = await getEventFromTxReceipt(receipt, swapContract);

// Make the API call
await sendEventDataToBackend(event);

Last updated