一、什麼是ethers.js
ethers.js庫旨在成為一個完整而緊湊的庫,用于與以太坊區塊鍊及其生态系統進行互動。它最初設計用于ethers.io,後來擴充為更通用的庫。官方連結:https://docs.ethers.io/ethers.js/html/getting-started.html
二、在Node.js中安裝
- (npm安裝) npm install -save ethers
- (yarn安裝) yarn add ethers
三、建立wallet.js檔案 生成錢包資訊
//引入ethers.js
var ethers = require('ethers');
//拿到生成的錢包資訊
var wallet = ethers.Wallet.createRandom();
//擷取助記詞
var mnemonic = wallet.mnemonic;
console.log("錢包助記詞:",mnemonic)
//擷取path
var path = wallet.path;
console.log("錢包path:",path)
//擷取錢包的私鑰
var privateKey = wallet.privateKey;
console.log("錢包私鑰:",privateKey)
//擷取錢包位址
var address = wallet.address;
console.log("錢包位址:",address)
在node中執行node wallet.js 可以看到錢包的助記詞、私鑰、位址已經生成成功。

四、根據私鑰找回錢包資訊
//引入ethers.js
var ethers = require('ethers');
//根據助記詞找回錢包資訊
var monic= "peace mouse scrap chase order guess volume unit riot save reopen nation"
var mnemonic = ethers.Wallet.fromMnemonic(monic);
var privateKey = mnemonic.privateKey;
console.log("錢包私鑰:",privateKey)
//根據私鑰找回錢包位址
var wallet = new ethers.Wallet(privateKey);
//錢包位址
var address = wallet.address;
console.log("錢包位址:",address)
在node中執行node wallet.js 可以看到錢包的私鑰、位址已經成功恢複。
學如逆水行舟,不進則退。心似平原跑馬,易放難收。全棧工程師是指掌握多種技能,并能利用多種技能獨立完成産品的人。 也叫全端工程師(同時具備前端和背景能力),英文Full Stack engineer。【人工智能】【區塊鍊】【系統/網絡/運維】【雲計算/大資料】【資料庫】【移動開發】【後端開發】【遊戲開發】【UI設計】【微服務】【爬蟲】【Java】【Go】【C++】【PHP】【Python】【Android/IOS】【HTML/CSS】【JavaScript】【Node】。。。
歡迎各位大神萌新一起專研分享各行各業技術!
IT全棧工程師技術交流群:593674370