web3.eth.accounts.create()生成异常对象

时间:2019-05-09 18:15:29

标签: node.js web3

我正在使用web3通过infura api创建一个帐户,但是它返回的对象与文档中所见的对象非常不同,并且该对象转换为Json时会产生错误

const account = web3.eth.accounts.create();
console.log('%o', account);
const jsonAccount = JSON.stringify(account);

结果:

{
   address: '0xa7b7f893309d49de4C7B4b83C4F2D633757e9480',
   privateKey:
    '0x1206fa9729d210e7c8461302f10c5604a241bd1c4260738a1bfa5f3f2663a987',
   accounts:
    Proxy [ Accounts {
        providerResolver:
         ProviderResolver { providersModuleFactory: ProvidersModuleFactory {} },
        givenProvider: null,
        _currentProvider:
         HttpProvider {
           host:
            'https://ropsten.infura.io',
           timeout: 0,
           headers: undefined,
           withCredentials: false,
           connected: true,
           providersModuleFactory: ProvidersModuleFactory {},
           agent: { httpsAgent: [Agent] } },
        _defaultAccount: undefined,
        _defaultBlock: 'latest',
        _transactionBlockTimeout: 50,
        _transactionConfirmationBlocks: 24,
        _transactionPollingTimeout: 750,
        _defaultGasPrice: undefined,
        _defaultGas: undefined,
        BatchRequest:
         { [Function]
           [length]: 0,
           [name]: '',
           [prototype]: { [constructor]: [Circular] } },
        utils:
         { [__esModule]: true,
           BN:
            { [Function: BN]
              [length]: 3,
              [name]: 'BN',
              [prototype]: [BN],
              BN: [Circular],
              wordSize: 26,
              isBN: [Function],
              max: [Function],
              min: [Function],
              red: [Function],
              _prime: [Function],
              mont: [Function] },
           randomHex:
            { [Function: randomHex]
              [length]: 2,
              [name]: 'randomHex',
              [arguments]: null,
              [caller]: null,
              [prototype]: [randomHex] },
           asciiToHex:
            { [Function: asciiToHex] [length]: 1, [name]: 'asciiToHex', [prototype]: [asciiToHex] },
           bytesToHex:
            { [Function: bytesToHex] [length]: 1, [name]: 'bytesToHex', [prototype]: [bytesToHex] },
           checkAddressChecksum:
            { [Function: checkAddressChecksum]
              [length]: 1,
              [name]: 'checkAddressChecksum',
              [prototype]: [checkAddressChecksum] },
           fromAscii:
            { [Function: asciiToHex] [length]: 1, [name]: 'asciiToHex', [prototype]: [asciiToHex] },
           fromDecimal:
            { [Function: numberToHex]
              [length]: 1,
              [name]: 'numberToHex',
              [prototype]: [numberToHex] },
           fromUtf8:
            { [Function: utf8ToHex] [length]: 1, [name]: 'utf8ToHex', [prototype]: [utf8ToHex] },
           fromWei:
            { [Function: fromWei] [length]: 2, [name]: 'fromWei', [prototype]: [fromWei] },
           getSignatureParameters:
            { [Function: getSignatureParameters]
              [length]: 1,
              [name]: 'getSignatureParameters',
              [prototype]: [getSignatureParameters] },
           getUnitValue:
            { [Function: getUnitValue]
              [length]: 1,
              [name]: 'getUnitValue',
              [prototype]: [getUnitValue] },
           hexToAscii:
            { [Function: hexToAscii] [length]: 1, [name]: 'hexToAscii', [prototype]: [hexToAscii] },
           hexToBytes:
            { [Function: hexToBytes] [length]: 1, [name]: 'hexToBytes', [prototype]: [hexToBytes] },
           hexToNumber:
            { [Function: hexToNumber]
              [length]: 1,
              [name]: 'hexToNumber',
              [prototype]: [hexToNumber] },
           hexToNumberString:
            { [Function: hexToNumberString]
              [length]: 1,
              [name]: 'hexToNumberString',
              [prototype]: [hexToNumberString] },
           hexToString:
            { [Function: hexToUtf8] [length]: 1, [name]: 'hexToUtf8', [prototype]: [hexToUtf8] },
           hexToUtf8:
            { [Function: hexToUtf8] [length]: 1, [name]: 'hexToUtf8', [prototype]: [hexToUtf8] },
           isAddress:
            { [Function: isAddress] [length]: 1, [name]: 'isAddress', [prototype]: [isAddress] },
           isBN:
            { [Function: isBN] [length]: 1, [name]: 'isBN', [prototype]: [isBN] },
           isBloom:
            { [Function: isBloom] [length]: 1, [name]: 'isBloom', [prototype]: [isBloom] },
           isHex:
            { [Function: isHex] [length]: 1, [name]: 'isHex', [prototype]: [isHex] },
           isHexStrict:
            { [Function: isHexStrict]
              [length]: 1,
              [name]: 'isHexStrict',
              [prototype]: [isHexStrict] },
           isTopic:
            { [Function: isTopic] [length]: 1, [name]: 'isTopic', [prototype]: [isTopic] },
           jsonInterfaceMethodToString:
            { [Function: jsonInterfaceMethodToString]
              [length]: 1,
              [name]: 'jsonInterfaceMethodToString',
              [prototype]: [jsonInterfaceMethodToString] },
           keccak256:
            { [Function: keccak256]
              [length]: 1,
              [name]: 'keccak256',
              [prototype]: [keccak256],
              _Hash: [Object] },
           numberToHex:
            { [Function: numberToHex]
              [length]: 1,
              [name]: 'numberToHex',
              [prototype]: [numberToHex] },
           padLeft:
            { [Function: leftPad] [length]: 3, [name]: 'leftPad', [prototype]: [leftPad] },
           padRight:
            { [Function: rightPad] [length]: 3, [name]: 'rightPad', [prototype]: [rightPad] },
           sha3:
            { [Function: keccak256]
              [length]: 1,
              [name]: 'keccak256',
              [prototype]: [keccak256],
              _Hash: [Object] },
           soliditySha3:
            { [Function: soliditySha3]
              [length]: 0,
              [name]: 'soliditySha3',
              [prototype]: [soliditySha3] },
           stringToHex:
            { [Function: utf8ToHex] [length]: 1, [name]: 'utf8ToHex', [prototype]: [utf8ToHex] },
           stripHexPrefix:
            { [Function: stripHexPrefix]
              [length]: 1,
              [name]: 'stripHexPrefix',
              [prototype]: [stripHexPrefix] },
           toAscii:
            { [Function: hexToAscii] [length]: 1, [name]: 'hexToAscii', [prototype]: [hexToAscii] },
           toBN:
            { [Function: toBN] [length]: 1, [name]: 'toBN', [prototype]: [toBN] },
           toChecksumAddress:
            { [Function: toChecksumAddress]
              [length]: 1,
              [name]: 'toChecksumAddress',
              [prototype]: [toChecksumAddress] },
           toDecimal:
            { [Function: hexToNumber]
              [length]: 1,
              [name]: 'hexToNumber',
              [prototype]: [hexToNumber] },
           toHex:
            { [Function: toHex] [length]: 2, [name]: 'toHex', [prototype]: [toHex] },
           toTwosComplement:
            { [Function: toTwosComplement]
              [length]: 1,
              [name]: 'toTwosComplement',
              [prototype]: [toTwosComplement] },
           toUtf8:
            { [Function: hexToUtf8] [length]: 1, [name]: 'hexToUtf8', [prototype]: [hexToUtf8] },
           toWei:
            { [Function: toWei] [length]: 2, [name]: 'toWei', [prototype]: [toWei] },
           utf8ToHex:
            { [Function: utf8ToHex] [length]: 1, [name]: 'utf8ToHex', [prototype]: [utf8ToHex] } },
        formatters:
         { outputBigNumberFormatter:
            { [Function: outputBigNumberFormatter]
              [length]: 1,
              [name]: 'outputBigNumberFormatter',
              [prototype]: [outputBigNumberFormatter] },
           isPredefinedBlockNumber:
            { [Function: isPredefinedBlockNumber]
              [length]: 1,
              [name]: 'isPredefinedBlockNumber',
              [prototype]: [isPredefinedBlockNumber] },
           inputDefaultBlockNumberFormatter:
            { [Function: inputDefaultBlockNumberFormatter]
              [length]: 2,
              [name]: 'inputDefaultBlockNumberFormatter',
              [prototype]: [inputDefaultBlockNumberFormatter] },
           inputBlockNumberFormatter:
            { [Function: inputBlockNumberFormatter]
              [length]: 1,
              [name]: 'inputBlockNumberFormatter',
              [prototype]: [inputBlockNumberFormatter] },
           txInputFormatter:
            { [Function: txInputFormatter]
              [length]: 1,
              [name]: 'txInputFormatter',
              [prototype]: [txInputFormatter] },
           inputCallFormatter:
            { [Function: inputCallFormatter]
              [length]: 2,
              [name]: 'inputCallFormatter',
              [prototype]: [inputCallFormatter] },
           inputTransactionFormatter:
            { [Function: inputTransactionFormatter]
              [length]: 2,
              [name]: 'inputTransactionFormatter',
              [prototype]: [inputTransactionFormatter] },
           inputSignFormatter:
            { [Function: inputSignFormatter]
              [length]: 1,
              [name]: 'inputSignFormatter',
              [prototype]: [inputSignFormatter] },
           outputTransactionFormatter:
            { [Function: outputTransactionFormatter]
              [length]: 1,
              [name]: 'outputTransactionFormatter',
              [prototype]: [outputTransactionFormatter] },
           outputTransactionReceiptFormatter:
            { [Function: outputTransactionReceiptFormatter]
              [length]: 1,
              [name]: 'outputTransactionReceiptFormatter',
              [prototype]: [outputTransactionReceiptFormatter] },
           outputBlockFormatter:
            { [Function: outputBlockFormatter]
              [length]: 1,
              [name]: 'outputBlockFormatter',
              [prototype]: [outputBlockFormatter] },
           inputLogFormatter:
            { [Function: inputLogFormatter]
              [length]: 1,
              [name]: 'inputLogFormatter',
              [prototype]: [inputLogFormatter] },
           outputLogFormatter:
            { [Function: outputLogFormatter]
              [length]: 1,
              [name]: 'outputLogFormatter',
              [prototype]: [outputLogFormatter] },
           inputPostFormatter:
            { [Function: inputPostFormatter]
              [length]: 1,
              [name]: 'inputPostFormatter',
              [prototype]: [inputPostFormatter] },
           outputPostFormatter:
            { [Function: outputPostFormatter]
              [length]: 1,
              [name]: 'outputPostFormatter',
              [prototype]: [outputPostFormatter] },
           inputAddressFormatter:
            { [Function: inputAddressFormatter]
              [length]: 1,
              [name]: 'inputAddressFormatter',
              [prototype]: [inputAddressFormatter] },
           outputSyncingFormatter:
            { [Function: outputSyncingFormatter]
              [length]: 1,
              [name]: 'outputSyncingFormatter',
              [prototype]: [outputSyncingFormatter] } },
        _transactionSigner:
         TransactionSigner {
           utils:
            { [__esModule]: true,
              BN: [Function],
              randomHex: [Function],
              asciiToHex: [Function],
              bytesToHex: [Function],
              checkAddressChecksum: [Function],
              fromAscii: [Function],
              fromDecimal: [Function],
              fromUtf8: [Function],
              fromWei: [Function],
              getSignatureParameters: [Function],
              getUnitValue: [Function],
              hexToAscii: [Function],
              hexToBytes: [Function],
              hexToNumber: [Function],
              hexToNumberString: [Function],
              hexToString: [Function],
              hexToUtf8: [Function],
              isAddress: [Function],
              isBN: [Function],
              isBloom: [Function],
              isHex: [Function],
              isHexStrict: [Function],
              isTopic: [Function],
              jsonInterfaceMethodToString: [Function],
              keccak256: [Function],
              numberToHex: [Function],
              padLeft: [Function],
              padRight: [Function],
              sha3: [Function],
              soliditySha3: [Function],
              stringToHex: [Function],
              stripHexPrefix: [Function],
              toAscii: [Function],
              toBN: [Function],
              toChecksumAddress: [Function],
              toDecimal: [Function],
              toHex: [Function],
              toTwosComplement: [Function],
              toUtf8: [Function],
              toWei: [Function],
              utf8ToHex: [Function] },
           formatters:
            { outputBigNumberFormatter: [Function],
              isPredefinedBlockNumber: [Function],
              inputDefaultBlockNumberFormatter: [Function],
              inputBlockNumberFormatter: [Function],
              txInputFormatter: [Function],
              inputCallFormatter: [Function],
              inputTransactionFormatter: [Function],
              inputSignFormatter: [Function],
              outputTransactionFormatter: [Function],
              outputTransactionReceiptFormatter: [Function],
              outputBlockFormatter: [Function],
              inputLogFormatter: [Function],
              outputLogFormatter: [Function],
              inputPostFormatter: [Function],
              outputPostFormatter: [Function],
              inputAddressFormatter: [Function],
              outputSyncingFormatter: [Function] } },
        defaultKeyName: 'web3js_wallet',
        accounts: {},
        accountsIndex: 0,
        wallet:
         Proxy [ Wallet {
             utils: [Object],
             accountsModule: Proxy [Array],
             defaultKeyName: 'web3js_wallet',
             accounts: {},
             accountsIndex: 0 },
           { get: [Function] } ] },
      { get:
         { [Function: get]
           [length]: 2,
           [name]: 'get',
           [prototype]: get { [constructor]: [Circular] } } } ] }

TypeError: Converting circular structure to JSON

但是web3文档:

https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html?highlight=remove#create

说输出应该像这样:

web3.eth.accounts.create();
> {
    address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
    privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
    signTransaction: function(tx){...},
    sign: function(data){...},
    encrypt: function(password){...}
}

可以帮我吗?

谢谢!

0 个答案:

没有答案