以太钱包(Ethereum Wallet)是用于存储、发送和接收以太币(ETH)及其他基于以太坊(Ethereum)的代币的工具。以下是以太钱包的基础概念、优势、类型、应用场景以及常见问题解答:
以太钱包通常包含一对公钥和私钥。公钥类似于银行账户,其他人可以向这个地址发送以太币;私钥则用于签署交易,证明你有权支配该地址的资金。
// 连接到MetaMask
if (typeof window.ethereum !== 'undefined') {
ethereum.request({ method: 'eth_requestAccounts' })
.then(accounts => {
const account = accounts[0];
console.log('Connected account:', account);
// 发送以太币
ethereum.request({
method: 'eth_sendTransaction',
params: [{
from: account,
to: '0xRecipientAddress',
value: '0xAmountInWei' // 例如:'0x2386F26FC10000' 表示0.1 ETH
}]
}).then(transactionHash => {
console.log('Transaction hash:', transactionHash);
}).catch(error => {
console.error('Error sending transaction:', error);
});
}).catch(error => {
console.error('Error connecting to MetaMask:', error);
});
} else {
console.log('MetaMask is not installed');
}
请确保在实际操作中仔细检查所有信息,特别是地址和金额,以避免资金损失。
领取专属 10元无门槛券
手把手带您无忧上云