Wallet Integration
HashNut supports integration with popular cryptocurrency wallets for seamless payment processing.
Supported Wallets
EVM-Compatible Chains
Primary Wallet: MetaMask (recommended for development)
WalletConnect Protocol: Enables connection to 100+ wallets
TRON Network
- TronLink: Official TRON wallet (Extension & Mobile)
- TronLink Pro: Advanced features
Wallet Connection Flow
MetaMask Integration
Installation
- Chrome/Edge: Chrome Web Store
- Firefox: Firefox Add-ons
- Mobile: iOS | Android
Connection Process
-
Detect MetaMask:
if (typeof window.ethereum !== 'undefined') {
// MetaMask is installed
} -
Request Connection:
await window.ethereum.request({ method: 'eth_requestAccounts' }); -
Get Account:
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
const account = accounts[0];
Network Switching
// Switch to Ethereum Sepolia testnet
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0xaa36a7' }], // Sepolia
});
TronLink Integration
Installation
- Chrome: Chrome Web Store
- Mobile: iOS | Android
Connection Process
-
Detect TronLink:
if (window.tronWeb && window.tronWeb.ready) {
// TronLink is installed and ready
} -
Get Account:
const account = window.tronWeb.defaultAddress.base58;
WalletConnect Integration
WalletConnect enables connection to 100+ wallets through a QR code or deep link.
How It Works
Implementation
import WalletConnect from '@walletconnect/client';
const connector = new WalletConnect({
bridge: 'https://bridge.hashnut.io', // HashNut bridge server
qrcodeModal: qrcode, // QR code modal
});
// Connect
await connector.connect();
// Send transaction
const result = await connector.sendTransaction({
from: account,
to: receiptAddress,
data: transactionData,
value: amount,
});
Payment Page Integration
HashNut's payment page automatically handles wallet integration:
- Auto-Detection: Detects installed wallets
- Connection Prompt: Guides user to connect
- Network Switching: Prompts to switch networks if needed
- Transaction Signing: Handles transaction approval
Developer Integration
For Custom Payment Pages
If building your own payment page:
- JavaScript
- React
// Detect and connect MetaMask
async function connectWallet() {
if (typeof window.ethereum !== 'undefined') {
try {
const accounts = await window.ethereum.request({
method: 'eth_requestAccounts'
});
return accounts[0];
} catch (error) {
console.error('Connection rejected:', error);
}
} else {
alert('Please install MetaMask!');
}
}
// Send payment transaction
async function sendPayment(receiptAddress, amount, tokenAddress) {
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const token = new ethers.Contract(tokenAddress, ERC20_ABI, signer);
const tx = await token.transfer(receiptAddress, amount);
return tx;
}
import { useWeb3 } from '@web3-react/core';
function PaymentButton({ order }) {
const { account, activate } = useWeb3();
const handlePayment = async () => {
if (!account) {
await activate(injected);
return;
}
// Send payment transaction
// ...
};
return (
<button onClick={handlePayment}>
{account ? 'Pay Now' : 'Connect Wallet'}
</button>
);
}
Network Configuration
Supported Networks
EVM Chains:
- Ethereum Mainnet (Chain ID: 1)
- Ethereum Sepolia (Chain ID: 11155111)
- Polygon Mainnet (Chain ID: 137)
- Polygon Mumbai (Chain ID: 80001)
- BSC Mainnet (Chain ID: 56)
- BSC Testnet (Chain ID: 97)
- And 150+ more...
TRON:
- TRON Mainnet
- TRON Shasta (Testnet)
Network Switching
HashNut payment page automatically:
- Detects current network
- Prompts to switch if wrong network
- Provides network switching instructions
Security Considerations
Transaction Verification
Always verify:
- ✅ Amount: Matches order amount exactly
- ✅ Recipient: Correct receipt address
- ✅ Token: Correct token contract address
- ✅ Network: Correct blockchain network
Best Practices
- Never Trust User Input: Always verify transaction parameters
- Validate Addresses: Check address format and checksum
- Confirm Network: Ensure user is on correct network
- Handle Rejections: Gracefully handle user transaction rejections
- Error Handling: Provide clear error messages
Troubleshooting
Wallet Not Detected
Solutions:
- Refresh page
- Check wallet extension is enabled
- Try different browser
- Check wallet is unlocked
Connection Rejected
Solutions:
- Check wallet permissions
- Clear browser cache
- Reinstall wallet extension
- Check for wallet updates
Wrong Network
Solutions:
- Use network switching prompt
- Manually switch in wallet
- Verify order chain matches wallet network
Transaction Failed
Solutions:
- Check sufficient balance
- Verify gas settings
- Check network congestion
- Retry transaction
Next Steps
- Create Orders: Start accepting payments
- Payment Page: Understand payment flow
- Error Handling: Handle wallet errors
Wallet connected? Create your First Order →