-
Notifications
You must be signed in to change notification settings - Fork 129
Contract events array not being populated #108
Comments
After some digging, I found this string of operations being performed during the initialization phase of drizzle. In What seems like an issue to me is that once the contract is initialized the events in the contract are set to an empty array. (Maybe we should be passing the events from if (action.type === 'CONTRACT_INITIALIZING') {
return {
...state,
[action.contractConfig.contractName]: generateContractInitialState(action.contractConfig)
}
}
if (action.type === 'CONTRACT_INITIALIZED')
{
return {
...state,
[action.name]: {
...state[action.name],
initialized: true,
synced: true,
events: []
}
}
} drizzle/src/contracts/contractsReducer.js (As stated above, the initial contract state is created with only functions from the ABI, no events. Because we need to provide events in import getAbi from './getAbi'
export function generateContractInitialState (contractConfig) {
var state = {
initialized: false,
synced: false
}
// Constant getters
var abi = getAbi(contractConfig)
for (var i2 = 0; i2 < abi.length; i2++) {
var item = abi[i2];
if (item.type == "function" && item.constant === true) {
state[item.name] = {}
}
}
return state drizzle/src/generateContractInitialState.js In function createContractEventChannel({contract, eventName, eventOptions}) {
const name = contract.contractName
return eventChannel(emit => {
const eventListener = contract.events[eventName](eventOptions).on('data', event => {
emit({type: 'EVENT_FIRED', name, event})
})
.on('changed', event => {
emit({type: 'EVENT_CHANGED', name, event})
})
.on('error', error => {
emit({type: 'EVENT_ERROR', name, error})
emit(END)
})
const unsubscribe = () => {
eventListener.removeListener(eventName)
}
return unsubscribe
})
} |
I ran into the issue that nothing about events was printed to the console. But obviously there must have been an error. Fixed it with that code: reime005@a449f16 |
For some reason, events aren't working for me either. I logged the error message, similar @reime005's suggestions and received this error:
It may be related to an issue with MetaMask not supporting web3 1.0 yet MetaMask/metamask-extension#3642 According to #10, Drizzle has a work around for this, but i'm not sure if it applies to events. |
@DiscRiskandBisque can you confirm that the #10 fix indeed doesn't cover events? I also get the "not supported" error (after exposing it manually): |
+ added proxy logic to smart contracts * separated smart contracts logic * fixed frontend calls with proper drizzle events listening using fallback Related issue: trufflesuite/drizzle#108 + added solhint config * updated migrations for new logic
Hi there, im having the same issue, i would like to know if there is any progress on it? thanks so much |
Good news from MetaMask, subscription support is underway: MetaMask/metamask-extension#5458 |
update to the latest metamask version, the event array its getting populated, and the websockets provider its working, im so so happy thanks |
Thanks for the update! |
drizzle v1.2.2
node v8.11.3
I would like to use drizzle to monitor events happening from my smart contract. Reading the docs I setup
drizzleOptions.js
with an array of strings that correspond to the contract's events, but when checking the state there are no events populated in the contract's event array.Here is the state tree (
events
array being a child ofSomeToken
contract):The text was updated successfully, but these errors were encountered: