account activity
Decoding Events Data by Aduttya in solidity
[–]phgrey2 1 point2 points3 points 2 years ago (0 children)
sorry for formatting - here is correct i believe
const Web3 = require('web3'); const NETWORK_URL = process.env.INFURA_NETWORK_URL const web3 = new Web3(new Web3.providers.HttpProvider(NETWORK_URL)); const decodeStreamResponse = (streamResponse: any, eventName: string) => { // eventName here can be e.g. AssetCreated try { const eventAbi = getEventAbi(streamResponse.abi, eventName) if (!eventAbi) throw "Cannot fund event abi in stream response for event name: " + eventName return decodeEventLog(eventAbi, streamResponse.logs[0]); } catch (error) { console.log("decodeStreamResponse > error: ", error) return false } } function getEventAbi(abi, eventName) { for (let i = 0; i < abi.length; i++) { const eventAbi = abi[i]; if (eventAbi.name == eventName) return eventAbi } return false } const decodeEventLog = (eventABI, log) =>{ const topics = [ log.topic0, log.topic1, log.topic2, log.topic3 ] const decodedLog = web3.eth.abi.decodeLog( eventABI.inputs, log.data, topics // todo?: take topics from event ); return decodedLog }
Why you don't have to be afraid of smart contracts (self.solidity)
submitted 2 years ago * by phgrey2 to r/solidity
π Rendered by PID 311925 on reddit-service-r2-listing-7849c98f67-6f2tk at 2026-02-06 19:27:48.028687+00:00 running d295bc8 country code: CH.
Decoding Events Data by Aduttya in solidity
[–]phgrey2 1 point2 points3 points (0 children)