Methods Overview
- cancelOffer – Cancel your offer and withdraw your deposit back from escrow.
1. cancelOffer
function cancelOffer(uint256 offerId) external;
What it does:
Cancels an active offer (created via makeOffer), moving your locked deposit back to you. On success, emits a CanceledOffer event.
Tip: Only the original maker can cancel, and only after the timelock has passed. Use offerId from the CreatedOffer event.
Parameters
| Name | Type | Description |
|---|---|---|
offerId | uint256 | Unique ID of the offer to cancel. |
Event Emitted
event CanceledOffer(
uint256 indexed offerId,
uint256 depositAssetAmountMakerReceived
);
offerId: the offer’s unique identifierdepositAssetAmountMakerReceived: the amount of your deposit refunded
Possible Errors
| Error | When You Might See It |
|---|---|
| Not the original maker | You’re not the maker of this offer. |
| Timelock period not passed | Cancelling before timelockPeriod has elapsed. |
| Offer already taken or cancelled | Offer is not active (already filled or cancelled). |
| Offer expired | Offer has passed its expiryTimestamp and cannot be canceled. |
Usage Tutorial
Example in TypeScript & Ethers.js
Copy-paste into cancelOffer.ts, install ethers, then npx ts-node cancelOffer.ts.
Prerequisites
- Node.js ≥16 & npm/yarn
- Polygon RPC endpoint (e.g.
https://polygon-rpc.com/) - Wallet private key with permissions (must be the maker)
1. Setup & Connect
import { ethers } from "ethers";
const RPC_URL = "https://polygon-rpc.com";
const PRIVATE_KEY = "YOUR_PRIVATE_KEY";
const DOTC_ADDRESS = ethers.getAddress("0x22593b8749A4e4854C449c30054Bb4D896374fa1");
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
// Minimal ABI for cancelOffer + event
const ABI = [
"function cancelOffer(uint256 offerId)",
"event CanceledOffer(uint256 indexed offerId, uint256 depositAssetAmountMakerReceived)"
];
const dotc = new ethers.Contract(DOTC_ADDRESS, ABI, wallet);
2. Define Offer ID
const OFFER_ID = 123; // replace with your offerId from CreatedOffer event
3. Submit & Listen
async function run() {
console.log("📡 Submitting cancelOffer...");
const tx = await dotc.cancelOffer(OFFER_ID);
console.log("🔗 Tx hash:", tx.hash);
const receipt = await tx.wait();
for (const ev of receipt.events ?? []) {
if (ev.event === "CanceledOffer") {
console.log("✅ Offer canceled!", {
offerId: ev.args![0].toString(),
refundedAmount: ev.args![1].toString()
});
}
}
}
run().catch(console.error);
4. Run It
npm install ethers
npx ts-node cancelOffer.ts
.png)