mantletestkit-sdk
v0.0.2
Published
A modern TypeScript SDK for interacting with the Mantle blockchain - transfer tokens, create contracts, and manage DeFi operations
Maintainers
Readme
mantletestkit-sdk
A modern TypeScript SDK for interacting with the Mantle blockchain - transfer tokens, create contracts, and manage DeFi operations. Works in both client-side (browser) and server-side environments.
🚀 Features
- Client-Side Ready: Works in Next.js, React, and other browser environments
- Server-Side Support: Traditional private key-based operations for backend services
- Token Operations: Transfer MNT and ERC20 tokens
- Token Creation: Deploy custom ERC20 tokens
- Token Burning: Burn tokens with visible events
- Balance Checking: Check MNT and token balances
- LangChain Integration: AI-powered blockchain interactions
- TypeScript Support: Full TypeScript support with types
- Modern API: Clean, promise-based API
📦 Installation
npm install mantletestkit-sdk🔧 Quick Start
Client-Side Usage (Next.js, React, Browser)
import { MantleSDK } from 'mantletestkit-sdk';
// Initialize the SDK (no private key needed!)
const mantleSDK = new MantleSDK();
// Connect to user's wallet (MetaMask, etc.)
const address = await mantleSDK.connect();
console.log('Connected wallet:', address);
// Check your MNT balance
const balance = await mantleSDK.getBalance();
console.log('MNT Balance:', balance);
// Transfer MNT (requires user approval)
const result = await mantleSDK.transfer({
toAddress: '0x1234567890123456789012345678901234567890',
amount: '0.001'
});
console.log('Transfer result:', result);Server-Side Usage (Node.js, Backend)
import { MantleAgent } from 'mantletestkit-sdk';
// Initialize the SDK with private key (server-side only!)
const mantleAgent = new MantleAgent({
rpcUrl: 'https://rpc.sepolia.mantle.xyz',
privateKey: process.env.PRIVATE_KEY!
});
// Check balance
const balance = await mantleAgent.getBalance();
console.log('MNT Balance:', balance);
// Transfer MNT
const result = await mantleAgent.transfer({
toAddress: '0x1234567890123456789012345678901234567890',
amount: '0.001'
});
console.log('Transfer result:', result);📚 API Reference
Client-Side SDK (MantleSDK)
const mantleSDK = new MantleSDK({
rpcUrl?: string // Optional, can use default
});
// Connect to wallet
await mantleSDK.connect();
// Check connection status
const isConnected = mantleSDK.getConnectionStatus();
// Get connected address
const address = await mantleSDK.getAddress();
// Check balance
const balance = await mantleSDK.getBalance();
const tokenBalance = await mantleSDK.getBalance('0xTokenAddress');
// Transfer (requires user approval)
await mantleSDK.transfer({
toAddress: '0x...',
amount: '0.001'
});
// Create token (requires user approval)
const tokenAddress = await mantleSDK.createToken({
name: 'MyToken',
symbol: 'MTK',
initialSupply: 1000
});Server-Side SDK (MantleAgent)
const mantleAgent = new MantleAgent({
rpcUrl: string, // Mantle RPC URL
privateKey: string // Your wallet private key
});
// All operations work the same way
const balance = await mantleAgent.getBalance();
const result = await mantleAgent.transfer({...});🌐 Environment Setup
Client-Side (.env.local)
# Optional - can use default RPC
MANTLE_RPC_URL=https://rpc.mantle.xyzServer-Side (.env)
# Required for server-side operations
MANTLE_RPC_URL=https://rpc.mantle.xyz
PRIVATE_KEY=your-private-key-here🔒 Security
- Client-Side: No private keys needed, uses user's wallet
- Server-Side: Private keys managed securely through environment variables
- User Approval: All client-side transactions require user approval
- Environment Variables: Use environment variables for sensitive server-side data
📝 Examples
Next.js Component Example
'use client';
import { useState, useEffect } from 'react';
import { MantleSDK } from 'mantletestkit-sdk';
export default function TransferComponent() {
const [sdk, setSdk] = useState<MantleSDK>();
const [address, setAddress] = useState<string>();
const [balance, setBalance] = useState<string>();
useEffect(() => {
const mantleSDK = new MantleSDK();
setSdk(mantleSDK);
}, []);
const connectWallet = async () => {
if (sdk) {
const addr = await sdk.connect();
setAddress(addr);
const bal = await sdk.getBalance();
setBalance(bal);
}
};
const transfer = async () => {
if (sdk) {
try {
const txHash = await sdk.transfer({
toAddress: '0x...',
amount: '0.001'
});
alert(`Transaction sent: ${txHash}`);
} catch (error) {
alert(`Error: ${error}`);
}
}
};
return (
<div>
{!address ? (
<button onClick={connectWallet}>Connect Wallet</button>
) : (
<div>
<p>Connected: {address}</p>
<p>Balance: {balance} MNT</p>
<button onClick={transfer}>Transfer 0.001 MNT</button>
</div>
)}
</div>
);
}🤖 LangChain Integration
The SDK includes full LangChain compatibility for AI-powered blockchain interactions:
import { MantleAI } from 'mantletestkit-sdk';
// Use with either client or server SDK
const mantleAI = new MantleAI({
openaiApiKey: 'your-openai-key',
mantleAgent: mantleSDK // or mantleAgent for server-side
});
await mantleAI.initialize();
// Natural language interactions
const balance = await mantleAI.invoke('What is my MNT balance?');
const transfer = await mantleAI.invoke('Transfer 0.001 MNT to 0x1234...');🌐 Network Configuration
Mantle Testnet (Sepolia)
const mantleSDK = new MantleSDK({
rpcUrl: 'https://rpc.sepolia.mantle.xyz'
});Mantle Mainnet
const mantleSDK = new MantleSDK({
rpcUrl: 'https://rpc.mantle.xyz'
});🤝 Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
