Ethereum 如何从帐户json文件读取私钥
我正在通过节点应用程序运行ganache cli:Ethereum 如何从帐户json文件读取私钥,ethereum,private-key,ganache,Ethereum,Private Key,Ganache,我正在通过节点应用程序运行ganache cli: const ganache = require('ganache-core'); const ethers = require('ethers'); const provider = new ethers.providers.Web3Provider( ganache.provider({ total_accounts: 5, account_keys_path: './accounts.json', gasPri
const ganache = require('ganache-core');
const ethers = require('ethers');
const provider = new ethers.providers.Web3Provider(
ganache.provider({
total_accounts: 5,
account_keys_path: './accounts.json',
gasPrice: 20000000000,
gasLimit: 20000000000,
default_balance_ether: 100
})
);
这将运行ganache cli并在accounts.json
中输出account详细信息。该文件如下所示:
{
"addresses":{
"0x73f5b3f74db1b37927696c280c04d544f4e9ff64":{
"secretKey":{
"type":"Buffer",
"data":[88, 17, .....]
},
"publicKey":{
"type":"Buffer",
"data":[13, 52, .....]
},
"address":"0x73f5b3f74db1b37927696c280c04d544f4e9ff64",
"account":{
"nonce":"0x",
"balance":"0x056bc75e2d63100000",
"stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"codeHash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
}
}
}
}
我可以看到帐户地址,但如何从该信息中解码/获取私钥?您无法直接从帐户获取私钥,但使用ganache cli有一些解决方法
--account\u keys\u path
选项将所有私钥保存到一个文件中,例如ganache cli--account\u keys\u path keys.json
。这将生成一个包含所有地址、私钥和公钥的json文件
--account
选项手动指定私钥和余额,例如ganache cli--account“0x31C354F57FC542EBA256699286723E94F7BD02A4891A0A7F68566C2A2DF679510000000000000000”
。这将分配1个ETH(=10000000000000000000000)与此私钥对应的地址。您可以使用不同的私钥多次使用--account
选项
您无法直接从帐户获取私钥,但使用ganache cli有一些解决方法
--account\u keys\u path
选项将所有私钥保存到一个文件中,例如ganache cli--account\u keys\u path keys.json
。这将生成一个包含所有地址、私钥和公钥的json文件
--account
选项手动指定私钥和余额,例如ganache cli--account“0x31C354F57FC542EBA256699286723E94F7BD02A4891A0A7F68566C2A2DF679510000000000000000”
。这将分配1个ETH(=10000000000000000000000)与此私钥对应的地址。您可以使用不同的私钥多次使用--account
选项