2

Following Drizzle documentation, Drizzle instance can only be created with:

const drizzle = new Drizzle(options)

Where the options is mandatory. And trying to not pass options will generate an error:

// The following will raise the error:
//   TypeError: Cannot read property 'contracts' of undefined
const drizzle = new Drizzle();

And when trying to pass an empty object {}, another error will be thrown:

// The following will raise the error:
//   TypeError: Cannot read property 'length' of undefined
const drizzle = new Drizzle({});

The idea is that: I want to create the Drizzle object in the constructor and later I will provide the data later dynamically:

var contractConfig = {
  contractName: "0x066408929e8d5Ed161e9cAA1876b60e1fBB5DB75",
  web3Contract: new web3.eth.Contract(/* ... */)
}
events = ['Mint']

// Using an action
dispatch({type: 'ADD_CONTRACT', drizzle, contractConfig, events, web3})

// Or using the Drizzle context object
this.context.drizzle.addContract(contractConfig, events)
2

Simply passing an empty array of contracts inside the type object, will solve the issues:

const options = {contracts: []}

this.drizzle = new Drizzle(options);

After this, data could be provided dynamically as in: https://truffleframework.com/docs/drizzle/getting-started/contract-interaction#adding-contracts-dynamically

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.