IAMC WebAssembly SDK
The IAMC WebAssembly SDK brings the complete power of the IAML toolchain to web environments, enabling you to compile, validate, and execute intent scripts directly in browsers and Node.js applications. Just a few method calls transform your intent scripts into executable blockchain transactions.
Quick Start
Installation
# Coming soon - SDK will be published to npm
npm install iamc-wasmNote: The IAMC WebAssembly SDK is currently in development and not yet published to npm. It will be available soon for public use.
Basic Intent Compilation
import init, { IamcWasm } from 'iamc-wasm';
import type { SourceFiles } from 'iamc-wasm';
async function compileBasicIntent(): Promise<void> {
await init();
const iamc = new IamcWasm();
try {
const sources: SourceFiles = {
'payment.iaml': `
contracts:
usdc:
abi: std/erc20
address: 0xA0b86a33E6441bC5569bac4D5E6Ba99a4C6C3f8b
constants:
recipient: !Address "0x742d35Cc6634C0532925a3b8D539b67b5b9f6567"
amount: !Uint 1000000 # 1 USDC
workflow:
- usdc.transfer(recipient, amount)
`
};
iamc.setSources(sources);
const result = iamc.compile({ target: 'payment.iaml' });
if (result.status === 'success') {
console.log('Bytecode:', result.data.bytecode);
}
} finally {
iamc.free();
}
}The compiled bytecode is complete transaction calldata ready to send to the Intentify Engine. You can submit this directly to the engine contract to execute your intent on-chain.
Core API
Working with Source Files
The SDK operates on in-memory source files, which makes it perfect for web environments where filesystem access isn’t available.
const sources: SourceFiles = {
'main.iaml': '...',
'solution.iaml': '...',
'utils.iasm.yaml': '...'
};
iamc.setSources(sources);Template System
The SDK supports powerful template functionality that allows you to create flexible, reusable intent scripts with runtime customization.
// Template with placeholders
const template = `
contracts:
token:
abi: std/erc20
address: 0x...
constants:
recipient: !Address 0x...
amount: !Uint 1000000
workflow:
- token.transfer(recipient, amount)
`;
// Update template with user input
const updateResult = iamc.update({
target: 'transfer.iaml',
field: 'constants.recipient',
value: { Address: '0x742d35Cc6634C0532925a3b8D539b67b5b9f6567' }
});Encoding Engine Input
The compile method always generates calldata for the Intentify Engine. For monolithic workflows, provide a single file. For multi-party workflows, provide multiple files that will be bundled together.
// Create calldata for monolithic workflow
const result = iamc.compile({ target: 'intent.iaml' });
// Create calldata for multi-party workflow
const result = iamc.compile({
targets: ['intent.iaml', 'solution.iaml']
});Decoding Engine Output
The SDK can decode both successful and failed execution results, providing detailed information about what happened during intent execution.
// Decode successful execution
const decoded = iamc.decode({
files: ['payment.iaml', 'solution.iaml'],
data: '0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000f4240',
error: false
});
/* Example decoded output:
{
"payment.iaml": {
"balance_before": 1500000000,
"balance_after": 500000000,
"transfer_amount": 1000000
},
"solution.iaml": {
"solver_fee": 5000,
"execution_gas": 21000
}
}
*/
// Decode failed execution
const errorDecoded = iamc.decode({
files: ['payment.iaml'],
data: '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001a496e73756666696369656e7420746f6b656e2062616c616e6365000000000000',
error: true
});
/* Example error output:
{
"payment.iaml": {
"error": "Insufficient token balance",
"failed_at_step": 2,
"data": {
"payment.iaml": {
"balance_before": 1500000000,
"balance_after": 0,
"transfer_amount": 0
}
}
}
}
*/Intentify your Workflow
When ad-hoc workflows don’t suffice, you need to sign your IAML scripts to create executable intents. This process adds metadata to your iaml file.
// Prepare script for signing and create signed intent
const prepareResult = iamc.prepareData({
target: 'intent.iaml',
chain_id: 1
});
if (prepareResult.status === 'success') {
const messageHash = prepareResult.data.message_hash;
// Get user signature (EIP-191 format)
const signature = await window.ethereum.request({
method: 'personal_sign',
params: [messageHash, userAddress]
});
// Add signature metadata to the IAML script
const intentResult = iamc.intentify({
target: 'intent.iaml',
signature: signature,
chain_id: 1
});
// Result: Signed IAML script ready for execution
console.log(intentResult.data.content);
/* Output:
---
signature: 0x1234567890abcdef...
chain_id: 1
ihash: 0xabcdef1234567890...
salt: 0x9876543210fedcba...
---
contracts:
usdc:
abi: std/erc20
address: 0xA0b86a33E6441bC5569bac4D5E6Ba99a4C6C3f8b
workflow:
- usdc.transfer(recipient, amount)
*/
}Why EIP-191? Since users already see the intent as structured IAML/YAML data, there’s no need for EIP-712’s additional structured data format. The IAML script itself serves as the readable representation of what the user is signing.