API Reference

To cancel an order(s) on X2Y2, follow the steps below.

Generate user signed message

Only order's maker could cancel the order. To verify the current user's address, two messages are necessary to be posted to X2Y2 server.

// Generate a Keccak256 hash of any string
const signMessage = ethers.utils.keccak256('0x')

// Ask user's wallet to sign the message
const sign = (await web3Provider.send('personal_sign', [
    signMessage,
    userAddress,
  ])) as string

Get input for order cancel

Call the Sign cancel order to get the necessary input to be submitted via wallet.

const cancelResponse = await post('https://api.x2y2.org/api/orders/cancel', JSON.stringify({
    caller: userAddress,
    op: 3,
    items: [{
        orderId: sellOrder.id
    }],
    sign_message: signMessage,
    sign,
}), {
    headers: {
        'Content-Type': 'application/json; charset=utf-8',
        'X-API-KEY': X2Y2_API_KEY,
    }
}
// Extract cancel input from cancelResponse…

Decode the input data

const inputData = ethers.utils.defaultAbiCoder.decode(
    [`tuple(bytes32[] itemHashes, uint256 deadline, uint8 v, bytes32 r, bytes32 s)`],
    cancelData.input
)[0]

const cancelInput = [inputData.itemHashes, inputData.deadline, inputData.v, inputData.r, inputData.s] as const

Submit the data to user's wallet

Submit the cancelInput decoded to buyer's wallet to finish the cancellation.

const marketContract = '0x74312363e45DCaBA76c59ec49a7Aa8A65a67EeD3' // X2Y2's market address on Mainnet. Use 0x1891EcD5F7b1E751151d857265D6e6D08ae8989e for Goerli testnet
const abi = [] // JSON format of X2Y2's market contract ABI, available at `https://etherscan.io/address/0x6d7812d41a08bc2a910b562d8b56411964a4ed88#code`
const market = new ethers.Contract(marketContract, abi, web3Provider)
const tx = await market.cancel(cancelInput)