使用 @ethersproject 系列套件建立錢包

使用@ethersproject旗下的系列套件時做一個具有註記的錢包 程式碼如下:

const ethWallet = require('@ethersproject/wallet')
const ethTx = require('@ethersproject/transactions')
import { computePublicKey } from '@ethersproject/signing-key'

const wallet = ethWallet.Wallet.createRandom() //隨機建立一個含有私鑰、註記詞的錢包

console.log(wallet.mnemonic.phrase) // 印出註記詞
console.log(wallet.publicKey) //印出公鑰
console.log(wallet.privateKey) //印出私鑰
console.log(wallet.address) //印出錢包地址

console.log(wallet.publicKey.substring(2)) //印出publicKeyHex
console.log(wallet.privateKey.substring(2)) //印出privateKeyHex
console.log(ethTx.computeAddress(wallet.publicKey)) //same to wallet.address

如果將privateKeyHex的值匯入metamask,會發現成功匯入,這個錢包的地址就是wallet.address!

DethCode - 在 etherscan 使用VScode查看合約

以Akutar Mint Pass這個合約為例 將網址中的 “.io” 改為 “.deth.net”,會跳轉到vscode ui的頁面,方便讀code、進行查詢 改成如下的網址: Vscode ui 介面:

有興趣可以去DethCode的github看更多詳細的細節與開源碼。

資料來源

eslint error-- mocha "describe" is not define

撰寫test檔時,發現以下eslint報的錯

解決辦法: .eslintrc檔案中加上:

"env": {
	"mocha": true
}

資料來源

解決 github page can not enable https 問題

購買網域並使用Cloudflare配置DNS後,想在github page勾選Enforce https讓網頁可以進行安全連線,卻發現如下問題:

原因: Cloudflare會預設啟用代理功能(顯示Proxied的橘色雲朵狀態),因此github沒辦法查看生成證書需要的DNS資訊。

解決方法: 將和github page有關的DNS設定改為灰色雲朵DNS only,回到github page頁面,重新設定一次custom domain。

資料來源

解決 invalid address or ENS name 問題

test 智能合約時,透過ethers.getSigners()建立Signer並使用 跑 npx hardhat test 發現問題:Error: invalid address or ENS name (argument=”name”, value=”<SignerWithAddress 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266>”, code=INVALID_ARGUMENT, version=contracts/5.6.0)

把alice使用console.log印出來看看

{from: alice} 改成 {from: alice.address} Problem solved!