phorcefield-sdk
v2.0.3
Published
Official Phorcefield Wallet SDK for dApp integration with AI-powered features
Maintainers
Readme
@phorcefield/sdk
The most powerful wallet SDK for Web3 developers
🚀 Why Phorcefield SDK?
The Phorcefield SDK isn't just another wallet integration library. It's the first Web3 SDK with built-in AI that gives your dApp superpowers:
Features That Surpass Phantom & MetaMask
| Feature | Phorcefield | Phantom | MetaMask | |---------|------------|---------|----------| | AI Portfolio Analytics | ✅ | ❌ | ❌ | | Transaction Explainer | ✅ | ❌ | ❌ | | Project Discovery Feed | ✅ | ❌ | ❌ | | Native Multi-Chain (SOL+SUI+ETH) | ✅ | Partial | ❌ | | Built-in Swap | ✅ | ❌ | ❌ | | Transaction Simulation | ✅ | ❌ | ❌ | | Batch Execute | ✅ | ❌ | ❌ | | TypeScript Support | ✅ | ✅ | ✅ | | Mobile Deep Linking | ✅ | ✅ | ✅ |
📦 Installation
# npm
npm install @phorcefield/sdk
# yarn
yarn add @phorcefield/sdk
# pnpm
pnpm add @phorcefield/sdkOr use via CDN:
<script src="https://cdn.phorcefield.io/sdk/v2/phorcefield-sdk.min.js"></script>⚡ Quick Start
import { PhorcefieldSDK } from '@phorcefield/sdk';
// 1. Initialize
const wallet = new PhorcefieldSDK({
appName: 'My Awesome DApp',
chains: ['SOLANA', 'SUI', 'ETHEREUM']
});
// 2. Connect
const { accounts } = await wallet.connect();
console.log('Connected:', accounts[0]);
// 3. Use AI features (unique to Phorcefield!)
const insights = await wallet.getPortfolioInsights();
console.log('AI Insights:', insights);
// 4. Sign and send transaction
const signature = await wallet.signAndSendTransaction(tx);🤖 AI-Powered Features
Portfolio Analytics
Get AI-driven insights about any wallet:
const analytics = await wallet.getPortfolioInsights(address);
console.log(analytics.insights);
// [
// { type: 'warning', category: 'Concentration', message: '80% in stablecoins' },
// { type: 'opportunity', category: 'DeFi', message: 'Consider yield opportunities' }
// ]
console.log(analytics.recommendations);
// ["Diversify into growth assets", "Explore SUI ecosystem"]Transaction Explainer
Educate users about what they're signing:
const explanation = await wallet.explainTransaction(tx);
console.log(explanation.summary);
// "You are swapping 100 USDC for approximately 0.5 SOL"
console.log(explanation.educationalNote);
// "A swap exchanges one token for another at current market rates..."Project Discovery
Surface new opportunities:
const projects = await wallet.discoverProjects('SOLANA', {
limit: 20,
daysOld: 30
});
console.log(projects.projects);
// [
// { name: 'Cool NFT Marketplace', symbol: 'COOL', daysOld: 5, ... },
// { name: 'New DeFi Protocol', symbol: 'DEFI', daysOld: 12, ... }
// ]🔗 Multi-Chain Support
Switch between chains seamlessly:
// Initialize with multiple chains
const wallet = new PhorcefieldSDK({
chains: ['SOLANA', 'SUI', 'ETHEREUM']
});
// Switch chain
await wallet.switchChain('SUI');
// Get balance on current chain
const balance = await wallet.getBalance();
// Or specific token
const usdcBalance = await wallet.getBalance('USDC');💱 Built-in Swap
No need for external DEX integrations:
// Get quote
const quote = await wallet.getSwapQuote({
from: 'SOL',
to: 'USDC',
amount: 1.0,
slippage: 0.5
});
console.log(`Rate: 1 SOL = ${quote.rate} USDC`);
console.log(`You'll receive: ${quote.toAmount} USDC`);
// Execute swap
const { signature } = await wallet.executeSwap(quote);
console.log('Swap successful:', signature);🛠 Developer Tools
Transaction Simulation
Test before sending:
const simulation = await wallet.simulateTransaction(tx);
if (simulation.result === 'success') {
console.log('Transaction will succeed!');
console.log('Compute units:', simulation.computeUnits);
} else {
console.error('Transaction will fail:', simulation.error);
}Gas Estimation
Accurate fee prediction:
const estimate = await wallet.estimateGas(tx);
console.log(`Estimated cost: ${estimate.totalCost} ${estimate.feeToken}`);
console.log(`Gas limit: ${estimate.gasLimit}`);Batch Execution
Execute multiple transactions:
const results = await wallet.batchExecute([tx1, tx2, tx3]);
console.log(`Success: ${results.successCount}/${results.results.length}`);
results.results.forEach((r, i) => {
if (r.success) {
console.log(`TX ${i}: ${r.signature}`);
} else {
console.error(`TX ${i} failed: ${r.error}`);
}
});📚 Full API Reference
Connection Methods
| Method | Description |
|--------|-------------|
| isInstalled() | Check if Phorcefield extension is installed |
| connect() | Request wallet connection |
| disconnect() | Disconnect from wallet |
| isConnected() | Check connection status |
| getAccounts() | Get connected accounts |
| getChain() | Get current blockchain |
| switchChain(chain) | Switch to different blockchain |
| getBalance(token?) | Get wallet balance |
Signing Methods
| Method | Description |
|--------|-------------|
| signMessage(message) | Sign a message |
| signTransaction(tx) | Sign a transaction |
| signAllTransactions(txs) | Sign multiple transactions |
| signAndSendTransaction(tx, options) | Sign and send transaction |
AI Features
| Method | Description |
|--------|-------------|
| getPortfolioInsights(address?, chain?) | Get AI portfolio analytics |
| explainTransaction(tx) | Get AI transaction explanation |
| discoverProjects(chain?, options?) | Discover new projects |
Swap Features
| Method | Description |
|--------|-------------|
| getSwapQuote(request) | Get swap quote |
| executeSwap(quote) | Execute swap |
Developer Tools
| Method | Description |
|--------|-------------|
| simulateTransaction(tx) | Simulate transaction |
| estimateGas(tx) | Estimate gas/fees |
| batchExecute(txs) | Execute multiple transactions |
Events
| Event | Data | Description |
|-------|------|-------------|
| connect | { accounts } | Wallet connected |
| disconnect | - | Wallet disconnected |
| accountChanged | { account } | Active account changed |
| chainChanged | { chainId } | Network changed |
🎯 Framework Examples
React
import { useState, useEffect } from 'react';
import { PhorcefieldSDK } from '@phorcefield/sdk';
function MyDApp() {
const [wallet] = useState(() => new PhorcefieldSDK({ appName: 'My DApp' }));
const [connected, setConnected] = useState(false);
const [insights, setInsights] = useState(null);
useEffect(() => {
wallet.on('connect', () => setConnected(true));
wallet.on('disconnect', () => setConnected(false));
}, [wallet]);
const handleConnect = async () => {
await wallet.connect();
// Load AI insights
const data = await wallet.getPortfolioInsights();
setInsights(data);
};
return (
<div>
{!connected && (
<button onClick={handleConnect}>Connect Wallet</button>
)}
{insights && (
<div>
<h3>AI Insights</h3>
{insights.insights.map((insight, i) => (
<p key={i}>{insight.message}</p>
))}
</div>
)}
</div>
);
}Next.js
'use client';
import { PhorcefieldSDK } from '@phorcefield/sdk';
export default function Page() {
const wallet = new PhorcefieldSDK({ appName: 'Next.js DApp' });
return (
<button onClick={() => wallet.connect()}>
Connect Wallet
</button>
);
}Vue
<script setup>
import { ref } from 'vue';
import { PhorcefieldSDK } from '@phorcefield/sdk';
const wallet = new PhorcefieldSDK({ appName: 'Vue DApp' });
const connected = ref(false);
wallet.on('connect', () => connected.value = true);
</script>
<template>
<button @click="wallet.connect()">
{{ connected ? 'Connected' : 'Connect Wallet' }}
</button>
</template>🔒 Security
- ✅ All signing happens in-wallet (keys never exposed)
- ✅ User approval required for all transactions
- ✅ HTTPS required for production
- ✅ Follows EIP-1193 standard
📖 Documentation
- Full Docs: https://docs.phorcefield.io/sdk
- API Reference: https://docs.phorcefield.io/sdk/api
- Examples: https://github.com/phorcefield/sdk-examples
- Discord: https://discord.gg/phorcefield
🤝 Support
- GitHub Issues: https://github.com/phorcefield/sdk/issues
- Discord: https://discord.gg/phorcefield
- Email: [email protected]
📄 License
MIT © Phorcefield Team
