Quickstart
Get from install to your first verified signing request in under 10 minutes.
Prerequisites: Node.js 18+, a Ledger device with the Ethereum app installed, and an API key from your Defimec account.
1. Install the SDK
npm install @defimec/sdk
2. Initialize the client
Create a client instance with your API key and the chains you'll use:
import { Defimec } from '@defimec/sdk'
const dfm = new Defimec({
apiKey: process.env.DEFIMEC_API_KEY,
chains: ['solana', 'base', 'arbitrum'],
ledger: {
transport: 'webusb', // or 'node-hid' for Node.js
},
rpc: {
healthProbe: true,
probeInterval: 30_000, // ms
},
})
3. Probe RPC health
Before routing any transaction, probe your configured RPCs:
const health = await dfm.rpc.probe('base')
if (!health.ok) {
console.error('RPC unhealthy:', health.reason)
// Defimec will use fallback RPC automatically
}
// health.chainId === 8453 (Base mainnet)
// health.blockLag === 0 (no lag)
4. Decode calldata before signing
Pass raw calldata through the decoder to see what you're actually signing:
const decoded = await dfm.decode({
chain: 'base',
data: '0xa9059cbb000000000000...',
})
// decoded.type === 'erc20_transfer'
// decoded.to === '0x1234...'
// decoded.amount === '500000000' (USDC units)
5. Sign with chain-ID verification
Route the transaction through Defimec. Chain-ID is verified before the hardware is asked to sign:
const result = await dfm.sign({
chain: 'base',
tx: {
to: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
data: decoded.raw,
value: '0x0',
},
verify: {
chainId: true, // HARD: verified before Ledger signs
rpcHealth: true,
calldataDecode: true,
},
})
// result.signature === '0x...'
// result.verified.chainId === true
// result.verified.rpcHealthy === true