ABI Topic Variables Break the Database

I’ve released new contracts and while adding new Sync&Watch Events plugins, I get the following error is server logs:

2021-09-01T14:38:41.963Z - Error: Error: Tried to encode an invalid date.
    at /moralis-server/lib/Controllers/DatabaseController.js:1184:21
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

My newly created table reads 9 items, but renders empty due to the bug:

Then got worse. I deleted all entries to the table and run it again. Table broke and I got a white page of death on https://gago4ywcuqck.usemoralis.com:2083/apps/moralisDashboard/browser/EthItemsForSale, also after server restart.

I changed the table name in the plugin to EthItemsForSaleNEW and ran sync again. Same thing, but the old EthItemsForSale link at least works again so I can delete it.

Yeeh :slight_smile:

Plugin data:

ItemAdded(bytes32,uint256,address,address,uint256,uint256)

ABI:

{
  "anonymous": false,
  "inputs": [
    {
      "indexed": false,
      "internalType": "bytes32",
      "name": "item_id",
      "type": "bytes32"
    },
    {
      "indexed": false,
      "internalType": "uint256",
      "name": "token_id",
      "type": "uint256"
    },
    {
      "indexed": false,
      "internalType": "address",
      "name": "token_address",
      "type": "address"
    },
    {
      "indexed": false,
      "internalType": "address",
      "name": "owner_of",
      "type": "address"
    },
    {
      "indexed": false,
      "internalType": "uint256",
      "name": "askingPrice",
      "type": "uint256"
    },
    {
      "indexed": false,
      "internalType": "uint256",
      "name": "expiresAt",
      "type": "uint256"
    }
  ],
  "name": "ItemAdded",
  "type": "event"
}

That ‘expiresAt’ uint256 is a unix timestamp number. Could that be the culprit? nah…
Example tx with event: https://rinkeby.etherscan.io/tx/0x95d9fa95ed347b65dcf611dd57c1c8739089f25f0e32c5d0bfb32170fbe883b0#eventlog

@ivan steps to reproduce:

  1. I’ve created a fresh server https://oc7cxh8z78qd.bigmoralis.com:2083/
  2. I’ve added a Sync Watch Events Plugin with my contract and event
  3. see table EthItemsForSale contains 30 items but dashboard display is broken
  4. see in logs Error: Tried to encode an invalid date. at /moralis-server/lib/Controllers/DatabaseController.js:1184:21 at processTicksAndRejections (internal/process/task_queues.js:95:5)

I see now what’s causing this. I have a few old events where I used the key ‘createdAt’ instead of ‘expiresAt’ on accident, causing a collision with the db’s own ‘createdAt’ field.
I since then upgraded the contract and ABI but of course the old events are still there and it’s still trying to sync historical.
Here is such an old event:
https://rinkeby.etherscan.io/tx/0x417f2fae6126da2767532c193eb9bf81f31a0429c2dde332d1e96c6861479283#eventlog
For the ABI see prev post.

I guess the best thing to do is deploy a new proxy contract! dooooh :woozy_face::hammer:

1 Like

Thanks!
You mean you used same DB table for different contracts with different ABI field names?

Not exactly, I had this by accident in my ABI:

{
      "indexed": false,
      "internalType": "uint256",
      "name": "createdAt",
      "type": "uint256"
    }

but should have been:

{
      "indexed": false,
      "internalType": "uint256",
      "name": "expiresAt",
      "type": "uint256"
    }

So when the sync plugin wants to save the data, there’s a collision with your internal ‘createdAt’ field, expecting a valid date and not uint256.
This breaks the dashboard UI.

That’s interesting collistion, will take to the team, thanks for discovering

I’ve deployed a fresh contract, so I don’t have old events anymore using ‘createdAt’ as a field.
https://rinkeby.etherscan.io/address/0x4e7d4334003478F12Bfd0c458e7E09De294BB04b#events

Sadly, database is still broken.

Deleted all old broken tables. Created NEW sync Plugins with a new contract and a NEW database table name. When I click this new one I get a white screen of death. Dashboard cannot load this table.

I don’t have errors anymore in the log.
Restarted several times, upgraded to .257

A show stopper as it fully breaks my marketplace. The only thing to do is start with a fresh server and migrate everything?
Possible someone could have a deeper look?
gago4ywcuqck.usemoralis.com



(white page)

Hi,
You could try to do a query to see what is in that EthMarketItem table. to see if is something suspicious there. Or you could delete that row that it has from a query too.

hi @cryptokid thanks, but it queries fine actually. It’s the Dashboard that’s broken.
It’s a newly created table by an event watch plugin.
Dashboard error:

Error: Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=Thu%20Jan%2001%201970%2001%3A00%3A00%20GMT%2B0100%20(Central%20European%20Standard%20Time)&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at Eo (dashboard.bundle.js:52)
    at dashboard.bundle.js:52
    at Na (dashboard.bundle.js:52)
    at gs (dashboard.bundle.js:52)
    at cl (dashboard.bundle.js:52)
    at sl (dashboard.bundle.js:52)
    at Zs (dashboard.bundle.js:52)
    at dashboard.bundle.js:52
    at t.unstable_runWithPriority (dashboard.bundle.js:60)
    at $i (dashboard.bundle.js:52)
es @ dashboard.bundle.js:52
n.callback @ dashboard.bundle.js:52
fo @ dashboard.bundle.js:52
os @ dashboard.bundle.js:52
pl @ dashboard.bundle.js:52
t.unstable_runWithPriority @ dashboard.bundle.js:60
$i @ dashboard.bundle.js:52
dl @ dashboard.bundle.js:52
Zs @ dashboard.bundle.js:52
(anonymous) @ dashboard.bundle.js:52
t.unstable_runWithPriority @ dashboard.bundle.js:60
$i @ dashboard.bundle.js:52
Vi @ dashboard.bundle.js:52
Hi @ dashboard.bundle.js:52
Gs @ dashboard.bundle.js:52
enqueueSetState @ dashboard.bundle.js:52
w.setState @ dashboard.bundle.js:44
(anonymous) @ dashboard.bundle.js:110
l @ dashboard.bundle.js:60
(anonymous) @ dashboard.bundle.js:60
forEach.e.<computed> @ dashboard.bundle.js:60
n @ dashboard.bundle.js:1
s @ dashboard.bundle.js:1
Promise.then (async)
n @ dashboard.bundle.js:1
s @ dashboard.bundle.js:1
(anonymous) @ dashboard.bundle.js:1
(anonymous) @ dashboard.bundle.js:1
(anonymous) @ dashboard.bundle.js:110
(anonymous) @ dashboard.bundle.js:110
l @ dashboard.bundle.js:60
(anonymous) @ dashboard.bundle.js:60
forEach.e.<computed> @ dashboard.bundle.js:60
n @ dashboard.bundle.js:1
s @ dashboard.bundle.js:1
Promise.then (async)
n @ dashboard.bundle.js:1
s @ dashboard.bundle.js:1
(anonymous) @ dashboard.bundle.js:1
(anonymous) @ dashboard.bundle.js:1
(anonymous) @ dashboard.bundle.js:110
value @ dashboard.bundle.js:110
bo @ dashboard.bundle.js:52
Pa @ dashboard.bundle.js:52
gs @ dashboard.bundle.js:52
cl @ dashboard.bundle.js:52
sl @ dashboard.bundle.js:52
Zs @ dashboard.bundle.js:52
(anonymous) @ dashboard.bundle.js:52
t.unstable_runWithPriority @ dashboard.bundle.js:60
$i @ dashboard.bundle.js:52
Vi @ dashboard.bundle.js:52
Hi @ dashboard.bundle.js:52
F @ dashboard.bundle.js:52
Yt @ dashboard.bundle.js:52
dashboard.bundle.js:52 Uncaught (in promise) Error: Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=Thu%20Jan%2001%201970%2001%3A00%3A00%20GMT%2B0100%20(Central%20European%20Standard%20Time)&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at Eo (dashboard.bundle.js:52)
    at dashboard.bundle.js:52
    at Na (dashboard.bundle.js:52)
    at gs (dashboard.bundle.js:52)
    at cl (dashboard.bundle.js:52)
    at sl (dashboard.bundle.js:52)
    at Zs (dashboard.bundle.js:52)
    at dashboard.bundle.js:52
    at t.unstable_runWithPriority (dashboard.bundle.js:60)
    at $i (dashboard.bundle.js:52)

It should be something related to what is in the ABI for that event.

yes i know, it’s all in the thread :slight_smile:
ABI was using ‘createdAt’ value, causing collision, but using a new contract now.

I shouldn’t matter the contract, only the ABI that you use when syncing the event.

Can you share the ABI that you used for that EthMarketItem plugin event sync?

found the issue, it seems moralis is interpreting ‘expiresAt’ as a Date type, while I want it as a UINT256.

{
  "anonymous": false,
  "inputs": [
    {
      "indexed": false,
      "internalType": "bytes32",
      "name": "item_id",
      "type": "bytes32"
    },
    {
      "indexed": false,
      "internalType": "uint256",
      "name": "token_id",
      "type": "uint256"
    },
    {
      "indexed": false,
      "internalType": "address",
      "name": "token_address",
      "type": "address"
    },
    {
      "indexed": false,
      "internalType": "address",
      "name": "owner_of",
      "type": "address"
    },
    {
      "indexed": false,
      "internalType": "uint256",
      "name": "askingPrice",
      "type": "uint256"
    },
    {
      "indexed": false,
      "internalType": "uint256",
      "name": "expiresAt",
      "type": "uint256"
    }
  ],
  "name": "ItemAdded",
  "type": "event"
}

In the output:

"expiresAt":{"__type":"Date","iso":"2000-01-01T00:00:00.000Z"}

(input is 0 in this case, I’ll try now with a valid timestamp too)

you can rename it to expire_at in the ABI only, and keeping the same contract

ha! that works thanks :partying_face:
so best to never use anything called xxxxAt ?

There are other restrictions too, like nothing that starts with _ too.

ok good to know! also good to know how to interpret a timestamp as a date type if I really want too :slight_smile:

cheers :raised_hands:

we have added to the backlog to rename automatically when a dev tries to give us ABI with forbidden variable names so soon it won’t be possible to submit such ABIs that don’t work with our DB :raised_hands::raised_hands:

perrrfect :raised_hands: :raised_hands: