Web3 SDK Reference
Status: WIP — Early Draft
This document provides a comprehensive reference for interacting with Cortensor smart contracts using the ethers.js library. It covers session and task management, along with contract event listening for dApp integrations.
Setup
Required Dependencies
npm install ethersConfiguration
const SESSION_V2_ADDRESS = "0x..."; // SessionV2 contract address
const SESSION_QUEUE_V2_ADDRESS = "0x..."; // SessionQueueV2 contract address
const PUBLIC_RPC_URL = "https://..."; // RPC URL for the networkRequired ABIs
SessionV2.json- ABI for the Session V2 contractSessionQueueV2.json- ABI for the Session Queue V2 contract
Session Management
create
createCreates a new session.
getSessions
getSessionsReturns all sessions owned by a user address.
getSession
getSessionReturns details for a session by ID.
getSessionMiners
getSessionMinersReturns ephemeral miners assigned to a session.
updateSession
updateSessionUpdates session configuration.
Task Management
submit
submitSubmits a task to the session.
getTasksBySessionId
getTasksBySessionIdReturns all tasks for a session.
getTaskResults
getTaskResultsReturns the results submitted by miners for a specific task.
Events
SessionV2 Contract Events
SessionCreated(uint256 sessionId, bytes32 sid, address owner, address[] miners)SessionUpdated(uint256 indexed sessionId, address indexed updater, uint256 minNumOfNodes, uint256 maxNumOfNodes, uint256 redundant)SessionDeactivated(uint256 indexed sessionId, address indexed deactivator)
SessionQueueV2 Contract Events
TaskQueued(uint256 sessionId, uint256 taskId, uint256 globalId, string taskData)TaskAssigned(uint256 sessionId, uint256 taskId, address[] miners)TaskEnded(uint256 sessionId, uint256 taskId, address[] miners)
Listening to Events
Notes
Use a secure provider (e.g. Alchemy, Infura)
Wrap contract calls in try/catch
Monitor for transaction failures
For production, use hardware wallets for signing
Error Handling
Session Modes
0: Ephemeral — shared miner pool1: Hybrid — dedicated + ephemeral2: Dedicated — exclusively dedicated miners
Last updated