How to save Logs/Events to DB in self-hosted server

β€œSync-on-chain-data-to-the-database” only contains parse setup, how can I save new events from contract to db

can you give more information about what you want to do?

you set up a webhook url, you receive the events in the webhook url and after that you can save that received data in your preferred database

@cryptokid I’ve created a new stream on the website and did setup of parse-server, but it is not saving those events in db.

you want to use parse server for that?

you can try to do some debugging to see what happens, to see if you receive the data, to see why it is not saved

I just want to know how can I save events from contract to db in self hosted server, I don’t have a Moralis hosted server so migration will not be used here?

@cryptokid please check above

I don’t know the context. What did you do by now?

@cryptokid I’ve created a stream and added webhook, now when the webhook is called the β€œreq.body” is undefined.

I want to receive that data and save it to db.

How you you read that req.body? You receive anything with that webhook request?

@cryptokid I’ve just created a simple express server of which endpoint/webhook I’ve added to the stream, when an event is emitted on the contract, there is a request to the webhook but nothing in the req body

ok, it should work fine with an express server, did you test it with a webhook url from webhook.site to see how the incoming request is expected to look like?

maybe print more info, like the http header, do you see info for the http header?

@cryptokid does the stream return events? Is it in the logs? How can I decode that, web3 decodeData doesn’t work on it, please refer to the following data retrieved from moralis

{
confirmed: true,
chainId: β€˜0xa869’,
abi: [
{
anonymous: false,
inputs: [Array],
name: β€˜Deposit’,
type: β€˜event’
}
],
streamId: β€˜24a34e56-cc65-4b63-a371-7d73488454f5’,
tag: β€˜XANAOWB’,
retries: 0,
block: {
number: β€˜16582414’,
hash: β€˜0x7b5e8cf8416d022bb8cf8a21406001c5383a44163848e59b26f1fddae5411855’,
timestamp: β€˜1670249621’
},
logs: [
{
logIndex: β€˜2’,
transactionHash: β€˜0xe03334f0be8c798c4e44941b7dfe78069f945ac590669ddf761062a37ae9c0f5’,
address: β€˜0xa193b32dee0f33c80b88e27cefae39b5a8fd3990’,
data: β€˜0x000000000000000000000000c969dc0b07ace3e99d6c2636e26d80086a90b8470000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000638dfc95000000000000000000000000000000000000000000000000000000000000002c’,
topic0: β€˜0x36af321ec8d3c75236829c5317affd40ddb308863a1236d2d277a4025cccee1e’,
topic1: null,
topic2: null,
topic3: null
}
],
txs: [
{
hash: β€˜0xe03334f0be8c798c4e44941b7dfe78069f945ac590669ddf761062a37ae9c0f5’,
gas: β€˜98461’,
gasPrice: β€˜26000000000’,
nonce: β€˜84’,
input: β€˜0xb6b55f250000000000000000000000000000000000000000000000000de0b6b3a7640000’,
transactionIndex: β€˜0’,
fromAddress: β€˜0xc969dc0b07ace3e99d6c2636e26d80086a90b847’,
toAddress: β€˜0xa193b32dee0f33c80b88e27cefae39b5a8fd3990’,
value: β€˜0’,
type: β€˜2’,
v: β€˜0’,
r: β€˜52613429329988332799292808020999707556370032921027628866103740236689491107819’,
s: β€˜47351151172851243189971094392156213312637209287201332767865929807870940107053’,
receiptCumulativeGasUsed: β€˜65641’,
receiptGasUsed: β€˜65641’,
receiptContractAddress: null,
receiptRoot: null,
receiptStatus: β€˜1’
}
],
txsInternal: [],
erc20Transfers: [],
erc20Approvals: [],
nftApprovals: { ERC1155: [], ERC721: [] },
nftTransfers: []
}

you can decode this event with that abi, there are various options to decode it, what is web3 decodeData?

you can use something like this