Search code examples
javascriptnode.jsecmascript-6ecmascript-5hyperledger-sawtooth

TypeError: Class constructor CryptoFactory cannot be invoked without 'new'


I want to use the sawtooth-sdk, and the guide code (https://sawtooth.hyperledger.org/docs/core/releases/latest/_autogen/sdk_submit_tutorial_js.html):

const {createContext, CryptoFactory} = require('sawtooth-sdk/signing')

const context = createContext('secp256k1')
const privateKey = context.newRandomPrivateKey()
const signer = CryptoFactory(context).newSigner(privateKey)

but error:

TypeError: Class constructor CryptoFactory cannot be invoked without 'new'

Solution

  • As the error states, you should change:

    const signer = CryptoFactory(context).newSigner(privateKey)
    

    to:

    const signer = (new CryptoFactory(context)).newSigner(privateKey)