创建钱包
如何使用 CLI 或以编程方式创建钱包
虽然钱包通常是通过Elrond网络钱包或Elrond总账应用创建的,但人们也可以使用 CLI 或 SDK。
生成新的助记符
使用 erdwalletjs-cli ,可以生成一个助记短语(24 个单词),如下所示:
erdwalletjs new-mnemonic --mnemonic-file=mnemonicOfAlice.txt
通过编程使用 elrond-core-js ,同样可以通过:
const core = require("@elrondnetwork/elrond-core-js");
let account = new core.account();
let mnemonic = account.generateMnemonic();
console.log(mnemonic);
【从助记符中导出一个 JSON 密钥文件】
使用 erdwalletjs-cli ,可以获得如下 JSON 密钥文件:
erdwalletjs derive-key --mnemonic-file=mnemonicOfAlice.txt \
--account-index=0 \
--key-file=keyOfAlice.json --password-file=passwordOfAlice.txt
通过编程使用 elrond-core-js ,同样可以通过:
const fs = require("fs");
const core = require("@elrondnetwork/elrond-core-js");
let mnemonic = "foo bar ...";
let password = "pass for JSON key-file";
let accountIndex = 0;
let account = new core.account();
let privateKeyHex = account.privateKeyFromMnemonic(mnemonic, false, accountIndex.toString(), "");
let privateKey = Buffer.from(privateKeyHex, "hex");
let keyFileObject = account.generateKeyFileFromPrivateKey(privateKey, password);
let keyFileJson = JSON.stringify(keyFileObject, null, 4);
fs.writeFileSync("myKeyFile.json", keyFileJson);