The Intuition Protocol SDK provides a powerful and intuitive interface for interacting with Intuition smart contracts. This package simplifies blockchain interactions by offering pre-built methods for reading from and writing to our smart contracts, handling wallet connections, and managing transactions.
npm install @intuition/protocol-sdk
yarn add @intuition/protocol-sdk
Initialize the Protocol SDK with your configuration:
import { IntuitionProtocol } from '@intuition/protocol-sdk';
const protocol = new IntuitionProtocol({
network: 'mainnet', // or 'testnet'
rpcUrl: 'YOUR_RPC_URL', // Optional: defaults to public RPC
chainId: 1 // Ethereum mainnet
});
Connect to various wallet providers:
// Connect to MetaMask
await protocol.connectWallet('metamask');
// Connect to WalletConnect
await protocol.connectWallet('walletconnect');
// Get connected account
const account = await protocol.getAccount();
// Listen for account changes
protocol.onAccountChange((account) => {
console.log('Account changed:', account);
});
getContractState - Get current contract stategetUserBalance - Get user's token balancegetTransactionHistory - Get historical transactionsexecuteTransaction - Send transactions to contractsapproveSpending - Approve token spendingbatchTransactions - Execute multiple transactions in one batchHere are some common contract interaction examples:
// Read contract data
const balance = await protocol.getUserBalance({
tokenAddress: '0x...',
userAddress: '0x...'
});
// Execute a transaction
const tx = await protocol.executeTransaction({
contractAddress: '0x...',
method: 'transfer',
params: {
to: '0x...',
amount: '1000000000000000000' // 1 token in wei
}
});
// Approve token spending
const approval = await protocol.approveSpending({
tokenAddress: '0x...',
spenderAddress: '0x...',
amount: '1000000000000000000'
});
The SDK provides robust transaction management features:
// Get transaction status
const status = await protocol.getTransactionStatus(txHash);
// Wait for transaction confirmation
const receipt = await protocol.waitForTransaction(txHash);
// Estimate gas costs
const gasEstimate = await protocol.estimateGas({
contractAddress: '0x...',
method: 'transfer',
params: {
to: '0x...',
amount: '1000000000000000000'
}
});
Listen to contract events:
// Subscribe to contract events
const subscription = protocol.subscribeToEvents({
contractAddress: '0x...',
eventName: 'Transfer',
callback: (event) => {
console.log('Transfer event:', event);
}
});
// Unsubscribe when done
subscription.unsubscribe();
If you need assistance with the Protocol SDK, you can: