import { createBaseAccountSDK } from "@base-org/account";
// Initialize the SDK
const provider = createBaseAccountSDK().getProvider();
// 1 — Prepare the typed data payload
const typedData = {
domain: {
name: 'Spend Permission Manager',
version: '1',
chainId: 8453, // or any other supported chain
verifyingContract: SPEND_PERMISSION_MANAGER_ADDRESS,
},
types: {
SpendPermission: [
{ name: 'account', type: 'address' },
{ name: 'spender', type: 'address' },
{ name: 'token', type: 'address' },
{ name: 'allowance', type: 'uint160' },
{ name: 'period', type: 'uint48' },
{ name: 'start', type: 'uint48' },
{ name: 'end', type: 'uint48' },
{ name: 'salt', type: 'uint256' },
{ name: 'extraData', type: 'bytes' },
],
},
primaryType: 'SpendPermission',
message: spendPermissionData,
};
// 2 — Request signature from user
try {
const accounts = await provider.request({
method: 'eth_requestAccounts'
});
const signature = await provider.request({
method: 'eth_signTypedData_v4',
params: [accounts[0], JSON.stringify(typedData)]
});
// 3 — Send to backend for verification
const response = await fetch('/typed-data/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
typedData,
signature,
address: accounts[0]
})
});
const result = await response.json();
console.log('Verification result:', result);
} catch (err) {
console.error('Signing failed:', err);
}