the-web3 / blockchain-question

MIT License
4 stars 0 forks source link

ethers@v6: ethers.Wallet不支持直接传入Buffer字节数组 #23

Open wureny opened 2 months ago

wureny commented 2 months ago
//在ethers v5中,以下代码可以成功运行
    const wallet = new ethers.Wallet(Buffer.from(privateKey, 'hex'));
    console.log(wallet.address)

//在ethers v6中,上述代码会出现报错,显示“invalid private key”
//可以直接传入hex字符串,会自动转换为uint8array
    const wallet = new ethers.Wallet(privateKey);
    console.log(wallet.address)
leo-shi-dacheng commented 2 months ago

v6真的更新了好多, 好多常见的方法都改名了,