How to get the all logs events of specific conctract from grpc node in nodeJs backend

I want to fetch all previous log events and subscribe for all future logs of a contract. i.e listen for events.
I wish to save the logs through NodeJs backend.
Kindly nudge us to right direction.

There is no place to get this historical data at the moment. You have to traverse the blocks and record them yourself.

The endpoint which has the transaction outcomes is the BlockSummary endpoint.

how to convert this data(blocksummary > transactionsummaries)


to this form
logs

You could try following approach:

  • Make hex to bytes conversion
  • Parse/decode bytes by event structure. Decoding must be by same rules, as encoding for contract.update parameters.

how to convert buffer data recieved from


in instanceInfo.model
to more readable form

That really depens on the smart contract. There is no general method, it depends on how your smart cotnract encodes its state.

Is there a reason why you are using V0 contracts? We strongly recommend you use V1 contracts and add view functions to get the data you want out of the contract.

they are Spaceseven’s NFT contracts. we are trying to fetch NFT data to display in our unity game. Through nodeJs via rpc node into our backend.

what would be the correct strategy according to you?

That depends a bit on the contract which I am not closely familiar with.

But I see two options.

Either the contract emits log events for the things you care about, in which case you should use the block summary and parse the events.

Or you should get the state (model) of the contract, and parse that. But the authors of the contract need to tell you the format of the state, I cannot.

If you show me the contract I can give more input. That can be done in private messages if you’d like.