Accounts

如何使用“testrpc –account”?

  • April 4, 2017

我正在嘗試為 testrpc 創建一個初始化腳本,該腳本在啟動時創建具有特定餘額的特定帳戶。

testrpc  --debug -account="aa73b5c98e60d589e71ce7cff59c02f82e12c7ce676ee356da8e058a285ccd61,100000"

生成以下

testrpc  --debug --account="aa73b5c98e60d589e71ce7cff59c02f82e12c7ce676ee356da8e058a285ccd61,100000"
/usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/solc/soljson.js:1
(function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["normalize"](filename);var ret=nodeFS["readFileS

RangeError: private key length is invalid
   at RangeError (native)
   at Object.exports.privateToPublic (/usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-util/index.js:356:20)
   at StateManager.createAccount (/usr/local/lib/node_modules/ethereumjs-testrpc/lib/statemanager.js:155:25)
   at Array.map (native)
   at StateManager.initialize (/usr/local/lib/node_modules/ethereumjs-testrpc/lib/statemanager.js:71:33)
   at new GethApiDouble (/usr/local/lib/node_modules/ethereumjs-testrpc/lib/subproviders/geth_api_double.js:21:14)
   at Object.Interface.provider (/usr/local/lib/node_modules/ethereumjs-testrpc/lib/interface.js:148:25)
   at Object.Interface.server (/usr/local/lib/node_modules/ethereumjs-testrpc/lib/interface.js:29:25)
   at Object.TestRPC.server (/usr/local/lib/node_modules/ethereumjs-testrpc/index.js:5:22)
   at Object

我使用的私鑰是在之前的 testrpc 執行中作為測試帳戶生成的:

可用帳戶

(0)0x22ddfe3c6439839edf8e2e56126c65c5fc5a2f40(1)0xc1da5556ecfc0ac4168d60bc8c884ae3dd6fba3f(2)0xb234a0c1afbd20e1f9a117272136aeaafaccb614(3)0xc8c206e296e92a475ee4c2bf9fb8d00d7ac83876(4)0x8b22109f827a7d6b16b085f9755e23a124a21709(5)0x34cb6cc7cc29f6ce978521ad691716fd7a3809c8(6)0xa3b692025e76530506a232188b6ecd681027585e(7)0x9b5a29122e80f8975d50a031b21e88adae489cf4(8)0xa921ef355a7d2729e7674a081aeeceff28419e23(9)0x444a798fad3ef318bfd7cee26c5937298cc2cbec

私鑰

(0)aa73b5c98e60d589e71ce7cff59c02f82e12c7ce676ee356da8e058a285ccd61(1)2337bf7968f70bcc7b1c04aba780b6157c3db9c575481c19e90f347f50c5df95(2)8d5cd323b43ee0fe3c3073bbbfa174d682ac8564164b2f253111ee591323a4f4(3)fccb97187708748a88c7dd7419c63fa3f5c125826116827f5459c72c2a07cd2a(4)032b517d15b77d0e8d8611beeb3e43021637c37fc4a6efcc40e6fa2fe0e20850(5)d5af034aa8990068eee4581012a4010fb78220293464ac3e39ca40f9cb79a873(6)9767f461cc6a1a0688e570846618547de95955d2bfeb37746c6997b7257e156e(7)dc6a7f0cd30f86da5e55ca7b62ac1a86f5d8b76a796176152803e0fcbc253900(8)52f3a1fa15405e1d5a68d7774ca45c7a3c7373a66c3c44db94a7f99a22c14d28

我也嘗試使用 HEX 餘額而不是整數並得到相同的結果。

根據testrpc 自述文件,您需要在私鑰前面粘貼一個 0x。

testrpc  --debug -account="0xaa73b5c98e60d589e71ce7cff59c02f82e12c7ce676ee356da8e058a285ccd61,100000"

添加 0x 前綴

引用自:https://ethereum.stackexchange.com/questions/11826