sureā¦
I have a table named āOffchainSalesā and input goes like this:
async function salePending(id) {
const OffchainSales = Moralis.Object.extend('OffchainSales')
const sales = new OffchainSales()
let tokenId = id.toString()
sales.set('tokenId', tokenId)
sales.set('status', 'pending')
try {
await sales.save()
console.log('sale saved', sales)
} catch (error) {
console.log(error)
}
}
Table input creates table and entry:
To query the table, I have the following:
async function queryPendingSale(id) {
let tokenId = web3.utils.hexToNumberString(id)
const query = new Moralis.Query('OffchainSales')
query.equalTo('tokenId', tokenId)
query.descending('createdAt')
query.limit(1)
const results = await query.find()
return results[0].attributes.status
}
Out of 10 queries it worked about 3 times and 7 times I get the following error in console:
Uncaught (in promise) TypeError: Cannot read property 'attributes' of undefined
When I remove search params (search by id, etc), I get this in console
sale status [ParseObject]
and sometimes I only get
sale status []
When it works, it clearly returns the status inside the table, which is awesome.
Thank you for your help and feedback.