跳到主要内容

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

  1. Chrome/Edge: Chrome Web Store
  2. Firefox: Firefox Add-ons
  3. Mobile: iOS | Android

Connection Process

  1. Detect MetaMask:

    if (typeof window.ethereum !== 'undefined') {
    // MetaMask is installed
    }
  2. Request Connection:

    await window.ethereum.request({ method: 'eth_requestAccounts' });
  3. 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
});

Installation

  1. Chrome: Chrome Web Store
  2. Mobile: iOS | Android

Connection Process

  1. Detect TronLink:

    if (window.tronWeb && window.tronWeb.ready) {
    // TronLink is installed and ready
    }
  2. 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:

  1. Auto-Detection: Detects installed wallets
  2. Connection Prompt: Guides user to connect
  3. Network Switching: Prompts to switch networks if needed
  4. Transaction Signing: Handles transaction approval

Developer Integration

For Custom Payment Pages

If building your own payment page:

// 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;
}

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

  1. Never Trust User Input: Always verify transaction parameters
  2. Validate Addresses: Check address format and checksum
  3. Confirm Network: Ensure user is on correct network
  4. Handle Rejections: Gracefully handle user transaction rejections
  5. 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


Wallet connected? Create your First Order →