在文档之后,微雨实例只能用以下方式创建:
const drizzle = new Drizzle(options)其中options是强制性的。并且试图不传递options将生成一个错误:
// The following will raise the error:
// TypeError: Cannot read property 'contracts' of undefined
const drizzle = new Drizzle();当试图传递空对象{}时,将引发另一个错误:
// The following will raise the error:
// TypeError: Cannot read property 'length' of undefined
const drizzle = new Drizzle({});我的想法是:我想在构造函数中创建微毛毛雨对象,稍后我将在动态中提供数据:
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)发布于 2019-02-19 20:35:16
只需在类型对象内传递一个空的契约数组,就可以解决以下问题:
const options = {contracts: []}
this.drizzle = new Drizzle(options);在此之后,可以动态地提供数据,如:https://truffleframework.com/docs/drizzle/getting-started/contract-interaction#adding-contracts-dynamically
https://ethereum.stackexchange.com/questions/67322
复制相似问题