Here’s how to connect a wallet (e.g., MetaMask) using Web3.js:
import Web3 from 'web3';
async function connectWallet() {
if (window.ethereum) {
const web3 = new Web3(window.ethereum);
try {
await window.ethereum.request({ method: 'eth_requestAccounts' });
const accounts = await web3.eth.getAccounts();
console.log('Connected account:', accounts[0]);
} catch (error) {
console.error('Wallet connection failed:', error);
}
} else {
console.log('MetaMask not detected.');
}
}
connectWallet();
Build secure, scalable, and feature-rich platforms tailored to your business needs. From blockchain integration to real-time trading, get end-to-end solutions for your crypto exchange project. Let's create the future of digital trading together with Cryptocurrency Exchange Development Services!"
Top comments (0)