Smart ContractsOn-Chain Infrastructure
Comprehensive guide to ML Bridge smart contracts, including architecture, deployment, and interaction patterns.
Core Contracts
The ML Bridge system consists of interconnected contracts handling different aspects of the ML workflow.
Main orchestration contract
Model metadata and versioning
Task lifecycle and execution
ERC-20 governance token
Validator staking and rewards
Performance and reputation
Contract Addresses
Deployed contract addresses on supported networks*
*Contract addresses will be published upon mainnet deployment.
Model Registry Contract
Manages ML model metadata, versioning, and access control.
registerModel()Register a new ML model with metadatafunction registerModel( string memory name, string memory description, string memory ipfsHash, ModelType modelType ) external returns (uint256 modelId)
updateModel()Update existing model metadatafunction updateModel( uint256 modelId, string memory newIpfsHash, uint256 newVersion ) external onlyModelOwner(modelId)
getModel()Retrieve model informationfunction getModel(uint256 modelId) external view returns (Model memory)
Task Manager Contract
Handles the lifecycle of ML inference tasks, from creation to completion.
Task Lifecycle
createTask()Create a new inference taskfunction createTask( uint256 modelId, string memory inputData, uint256 reward ) external payable returns (uint256 taskId)
submitResult()Submit task execution resultfunction submitResult( uint256 taskId, string memory result, bytes memory proof ) external onlyValidator
Governance Token (MLB)
- ERC-20 compatible governance token
- Used for voting on protocol upgrades
- Earned through validation and staking
- Required for proposal creation
Staking Parameters
Integration Examples
Examples of how to interact with ML Bridge smart contracts using Web3 libraries.
Web3.js Example
// Register a new model
const contract = new web3.eth.Contract(
abi, contractAddress
);
const result = await contract.methods
.registerModel(
"My ML Model",
"A powerful classification model",
"QmXxXxXxXxXxXxXxXxXxXxXx",
0 // ModelType.CLASSIFICATION
)
.send({ from: userAddress });Ethers.js Example
// Create an inference task
const contract = new ethers.Contract(
address, abi, signer
);
const tx = await contract.createTask(
modelId,
JSON.stringify(inputData),
ethers.utils.parseEther("0.1"),
{ value: ethers.utils.parseEther("0.1") }
);
await tx.wait();Security Notes
- Always verify contract addresses before interacting
- Use proper access controls for sensitive operations
- Implement reentrancy guards where necessary
- Validate all input parameters
Deployment Prerequisites
- Node.js 16+ and npm/yarn
- Hardhat development environment
- Network RPC endpoints
- Deployment wallet with sufficient gas