EVM Signature#
EVM Signature SDK#
// signOrderRFQ.js
import { Wallet, ethers } from "ethers";
/**
* Sign an OrderRFQ-typed struct and return the signature string
*
* @param {string} privateKey - Signer's private key (EOA)
* @param {string} verifyingContract - Address of the contract used for signature verification
* @param {number} chainId - Current chain ID
* @param {object} order - Order object containing fields like rfqId, expiration, etc.
* @returns {Promise<string>} - EIP-712 signature string
*/
export async function signOrderRFQ({ privateKey, verifyingContract, chainId, order }) {
const wallet = new Wallet(privateKey);
const domain = {
name: "OKX Lab PMM Protocol",
version: "1.0",
chainId,
verifyingContract,
};
const types = {
OrderRFQ: [
{ name: "rfqId", type: "uint256" },
{ name: "expiry", type: "uint256" },
{ name: "makerAsset", type: "address" },
{ name: "takerAsset", type: "address" },
{ name: "makerAddress", type: "address" },
{ name: "makerAmount", type: "uint256" },
{ name: "takerAmount", type: "uint256" },
{ name: "usePermit2", type: "bool" },
],
};
const signature = await wallet.signTypedData(domain, types, order);
return signature;
}
EVM Signing Example#
import { signOrderRFQ } from "./signOrderRFQ.js";
import { ethers } from "ethers";
const currentTime = Math.floor(Date.now() / 1000);
const expiry = currentTime + 90;
const sig = await signOrderRFQ({
// foundry local public test account
privateKey: "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
// PMM settlement contract (`pool` as adapter's perspective)
verifyingContract: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
chainId: 31337,
order: {
rfqId: 1,
expiry: expiry,
makerAsset: "0x111111111117dC0aa78b770fA6A738034120C302",
takerAsset: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
makerAddress: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
// 100000000000000000000
makerAmount: ethers.parseUnits("100", 18),
// 500000000000000000
takerAmount: ethers.parseUnits("0.5", 18),
usePermit2: false,
},
});
console.log("Signature:", sig);
Table of contents