ABI Format and Data Structures
Contract Structure
After importing a contract, it will have the following structure:
interface Contract {
/** Contract ID in MOUNTAIN */
id: number;
/** Project ID */
projectId: number;
/** Network ID where the contract is deployed */
networkId: number;
/** Contract address */
address: string;
/** Contract type (always 'imported' for imported contracts) */
type: 'imported';
/** Formatted ABI functions */
formattedAbi: string[];
}
Formatted ABI Requirements
MOUNTAIN uses a specific ABI format for better type safety and parsing:
// ❌ Raw ABI (not supported)
const rawAbi = [
{
inputs: [
{ name: 'to', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
name: 'mint',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
];
// ✅ Formatted ABI (required)
const formattedAbi = [
'function mint(address to, uint256 amount)',
'event Transfer(address indexed from, address indexed to, uint256 value)',
];
// ✅ For single event definitions (used in Event Notifier)
const formattedAbiEvent = 'event Transfer(address indexed from, address indexed to, uint256 value)';
Converting ABI Format
You can use abitype
to convert raw ABI to formatted ABI:
import { formatAbi, formatAbiItem } from 'abitype';
// For full contract ABI
const rawAbi = [...]; // Your raw ABI
const formattedAbi = formatAbi(rawAbi);
// For individual functions or events (used in Event Notifier)
const rawEventAbi = {
anonymous: false,
inputs: [
{ indexed: true, name: 'from', type: 'address' },
{ indexed: true, name: 'to', type: 'address' },
{ indexed: false, name: 'value', type: 'uint256' },
],
name: 'Transfer',
type: 'event',
};
const formattedAbiEvent = formatAbiItem(rawEventAbi);
// Result: 'event Transfer(address indexed from, address indexed to, uint256 value)'
ABI Management Best Practices
Include Only Necessary Functions
- Only include functions you plan to use
- Include relevant events for monitoring
- ABI validation happens automatically at import time
Validation
- ABI validation is performed when importing contracts and creating event subscriptions
- Invalid ABIs will be rejected with detailed error messages
- Use
abitype
'sformatAbi()
for contracts andformatAbiItem()
for individual events - Event Notifier subscriptions require properly formatted event definitions
Next Steps
- Import your contract with proper ABI format
- Manage contract functions after import
- Review best practices for secure management