Actions API
Programmatic API for blockchain interactions. Use actions when you need custom implementations or want to build your own UI components.
Overview
The Actions API provides programmatic access to blockchain operations. Instead of using pre-built components, you can use actions to create custom implementations with full control over the UI and flow.
When to Use Actions
Use the Actions API when you need custom UI implementations, want to integrate Hyperkit functionality into existing components, or need more control over the transaction flow.
Creating Actions
Create an actions instance using createBlockchainActions:
CreateActions.ts
import { createBlockchainActions } from 'hyperkit';
import { ethers } from 'ethers';
// Get provider and signer from wallet
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
// Create actions instance
const actions = createBlockchainActions(provider, signer);Available Methods
Token Actions
- •
getTokenBalance(tokenSymbol, userAddress)- Get token balance - •
approveToken(tokenSymbol, spenderAddress, amount)- Approve token spending - •
getAllowance(tokenSymbol, ownerAddress, spenderAddress)- Get token allowance
Swap Actions
- •
getSwapQuote(tokenIn, tokenOut, amountIn)- Get swap quote - •
swapTokens(tokenIn, tokenOut, amountIn, expectedAmountOut, recipient, slippageTolerance)- Execute swap
Staking Actions
- •
stakeTokens(amount)- Stake tokens - •
unstakeTokens(amount)- Unstake tokens - •
getStakingBalance(userAddress)- Get staking balance - •
claimRewards()- Claim staking rewards
Bridge Actions
- •
bridgeTokens(tokenSymbol, amount, targetChainId, recipient)- Bridge tokens - •
getBridgeQuote(tokenSymbol, amount, targetChainId)- Get bridge quote
Usage Examples
ActionsExample.ts
import { createBlockchainActions } from 'hyperkit';
// Create actions instance
const actions = createBlockchainActions(provider, signer);
// Get token balance
const balance = await actions.getTokenBalance('USDT', userAddress);
// Get swap quote
const quote = await actions.getSwapQuote('USDT', 'USDC', '100');
// Execute swap
await actions.swapTokens(
'USDT',
'USDC',
'100',
quote.outputAmount,
recipient,
0.5 // 0.5% slippage
);
// Stake tokens
await actions.stakeTokens('1000');