A standalone implementation of Hyperliquid staking functionality extracted from the Validao referral system. This provides wallet integration, staking/unstaking operations, and balance management for the Hyperliquid blockchain.
- π Wallet Integration: Connect via MetaMask, WalletConnect, and other popular wallets using RainbowKit
- π° Staking Operations: Stake and unstake HYPE tokens with ValiDAO validators
- π Balance Management: View wallet, staked, spot, and pending rewards balances
- π Transfer Support: Transfer HYPE from spot to staking balance
- π Network Support: Both mainnet and testnet configurations
- π― Referral System: Optional referral code support for tracking delegations
npm installTo use WalletConnect, you'll need to get a project ID:
- Go to https://cloud.walletconnect.com
- Create a new project
- Copy your project ID
- Update
src/lib/walletProvider.tsx:
const config = getDefaultConfig({
appName: "Hyperliquid Staking",
projectId: "YOUR_WALLETCONNECT_PROJECT_ID", // <-- Add your ID here
// ...
});npm run devThis will start the development server at http://localhost:5173
npm run buildThis creates a production build in the dist folder.
import { HyperliquidStaking, WalletProvider } from 'hyperliquid-staking';
function App() {
return (
<WalletProvider>
<HyperliquidStaking
isTestnet={false} // Use mainnet (default)
referralCode="your-code" // Optional referral tracking
/>
</WalletProvider>
);
}import { useHyperliquidStaking } from 'hyperliquid-staking';
function MyComponent() {
const {
chain,
data,
loading,
stake,
unstake,
isConnected,
address
} = useHyperliquidStaking(false); // false for mainnet, true for testnet
const handleStake = async () => {
try {
const result = await stake(10, "optional-referral-code");
console.log("Staked successfully:", result.transactionHash);
} catch (error) {
console.error("Staking failed:", error);
}
};
return (
<div>
<p>Wallet Balance: {data.balance} HYPE</p>
<p>Staked Amount: {data.stakedAmount} HYPE</p>
<button onClick={handleStake}>Stake 10 HYPE</button>
</div>
);
}HyperliquidStaking: Main UI component for staking interfaceWalletProvider: Wagmi and RainbowKit provider wrapperuseHyperliquidStaking: React hook for staking operations
- Mainnet: Arbitrum One (Chain ID: 42161)
- Testnet: Arbitrum Sepolia (Chain ID: 421614)
- Token: HYPE with 8 decimals
src/
βββ components/
β βββ HyperliquidStaking.tsx # Main staking UI component
βββ hooks/
β βββ useHyperliquidStaking.ts # Staking operations hook
βββ lib/
β βββ chains/
β β βββ hyperliquid/
β β βββ adapter.ts # Wallet adapter implementation
β β βββ api.ts # Hyperliquid API client
β β βββ hyperliquid.ts # Mainnet configuration
β β βββ hyperliquid-testnet.ts # Testnet configuration
β βββ utils.ts # Utility functions
β βββ walletProvider.tsx # Wallet connection provider
βββ index.ts # Library exports
const result = await stake(amount, referralCode);
// Returns: { transactionHash: string, height: number }const result = await unstake(amount);
// Returns: { transactionHash: string }The Hyperliquid adapter includes a method to transfer HYPE from spot balance to staking balance:
const adapter = walletAdapter as HyperliquidWalletAdapter;
await adapter.transferFromSpotToPerp(amount);Hyperliquid uses EIP-712 typed data signatures for staking operations:
- Domain:
HyperliquidSignTransaction - Types:
HyperliquidTransaction:TokenDelegate - Chain ID: Arbitrum chain IDs
npm run typecheckYou can customize the UI by modifying the Tailwind CSS classes in HyperliquidStaking.tsx or create your own component using the useHyperliquidStaking hook.
- React 18+
- Wagmi 2.12+
- RainbowKit 2.2+
- Viem 2.21+
- Ethers 6.13+
- TailwindCSS 3.4+
Extracted from Validao Referral System