Files
smom-dbis-138/metamask-sdk/README.md
defiQUG 1fb7266469 Add Oracle Aggregator and CCIP Integration
- Introduced Aggregator.sol for Chainlink-compatible oracle functionality, including round-based updates and access control.
- Added OracleWithCCIP.sol to extend Aggregator with CCIP cross-chain messaging capabilities.
- Created .gitmodules to include OpenZeppelin contracts as a submodule.
- Developed a comprehensive deployment guide in NEXT_STEPS_COMPLETE_GUIDE.md for Phase 2 and smart contract deployment.
- Implemented Vite configuration for the orchestration portal, supporting both Vue and React frameworks.
- Added server-side logic for the Multi-Cloud Orchestration Portal, including API endpoints for environment management and monitoring.
- Created scripts for resource import and usage validation across non-US regions.
- Added tests for CCIP error handling and integration to ensure robust functionality.
- Included various new files and directories for the orchestration portal and deployment scripts.
2025-12-12 14:57:48 -08:00

158 lines
3.3 KiB
Markdown

# MetaMask SDK for ChainID 138
MetaMask integration helpers for DeFi Oracle Meta Mainnet (ChainID 138).
## Installation
```bash
npm install @defi-oracle/metamask-sdk
```
Or using the source:
```bash
cd metamask-sdk
npm install
npm run build
```
## Usage
### Add Network to MetaMask
```typescript
import { addNetwork, addOrSwitchNetwork } from '@defi-oracle/metamask-sdk';
// Add ChainID 138 to MetaMask
await addNetwork();
// Or add if not added, switch if already added
await addOrSwitchNetwork();
```
### Switch to ChainID 138
```typescript
import { switchNetwork, isOnChain138 } from '@defi-oracle/metamask-sdk';
// Check if already on ChainID 138
const isOn138 = await isOnChain138();
if (!isOn138) {
await switchNetwork();
}
```
### Add Token to MetaMask
```typescript
import { addToken } from '@defi-oracle/metamask-sdk';
// Add WETH token
await addToken(
'0xYourTokenAddress',
'WETH',
18,
'https://explorer.d-bis.org/images/tokens/weth.png'
);
```
### Complete Example
```typescript
import { addOrSwitchNetwork, addToken, isOnChain138 } from '@defi-oracle/metamask-sdk';
async function connectToChain138() {
try {
// Add or switch to ChainID 138
await addOrSwitchNetwork();
// Verify we're on the correct chain
const isOn138 = await isOnChain138();
if (!isOn138) {
throw new Error('Failed to switch to ChainID 138');
}
console.log('Connected to ChainID 138');
} catch (error) {
console.error('Error connecting to ChainID 138:', error);
}
}
async function addWETHToken() {
try {
await addToken(
'0xYourWETHAddress',
'WETH',
18,
'https://explorer.d-bis.org/images/tokens/weth.png'
);
console.log('WETH token added to MetaMask');
} catch (error) {
console.error('Error adding token:', error);
}
}
```
## API Reference
### Network Functions
- `addNetwork(customMetadata?)` - Add ChainID 138 to MetaMask
- `switchNetwork()` - Switch to ChainID 138
- `addOrSwitchNetwork()` - Add if not added, switch if already added
- `isNetworkAdded()` - Check if ChainID 138 is added
- `isOnChain138()` - Check if currently on ChainID 138
- `getCurrentChainId()` - Get current chain ID
### Token Functions
- `addToken(address, symbol, decimals, image?)` - Add ERC-20 token
- `addTokenFromList(token)` - Add token from token list entry
### Configuration
- `CHAIN_ID` - ChainID (138)
- `CHAIN_ID_HEX` - ChainID in hex (0x8a)
- `CHAIN_NAME` - Chain name
- `RPC_URLS` - RPC endpoint URLs
- `BLOCK_EXPLORER_URL` - Blockscout explorer URL
- `NETWORK_METADATA` - Network metadata for wallet_addEthereumChain
- `CAIP2_IDENTIFIER` - CAIP-2 identifier (eip155:138)
## Error Handling
All functions throw errors that should be caught:
```typescript
try {
await addNetwork();
} catch (error) {
if (error.message.includes('MetaMask is not installed')) {
// Handle MetaMask not installed
} else if (error.message.includes('User rejected')) {
// Handle user rejection
} else {
// Handle other errors
}
}
```
## Browser Compatibility
- Chrome/Chromium (MetaMask Extension)
- Firefox (MetaMask Extension)
- Edge (MetaMask Extension)
- Mobile browsers (MetaMask Mobile)
## Requirements
- MetaMask extension or mobile app installed
- MetaMask unlocked
- User approval for network addition/switching
## License
MIT