How to use the web3-eth-abi.decodeLog function in web3-eth-abi

To help you get started, we’ve selected a few web3-eth-abi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Ethercast / serverless-blockstream / src / util / abi / decoder.ts View on Github external
export function decodeLogParameters(log: Log, abi: Abi): DecodedLog {
  // first find the matching signature
  const matchingSignature = _.find(
    abi,
    abiSignature =>
      abiSignature.type === 'event' &&
      !abiSignature.anonymous &&
      encodeEventSignature(abiSignature) === log.topics[ 0 ]
  );

  if (!matchingSignature) {
    throw new Error('found abi but failed to find matching event signature');
  }

  const parameters = decodeLog(matchingSignature.inputs, log.data, log.topics);

  return {
    ...log,
    ethercast: {
      eventName: matchingSignature.name || '',
      parameters
    }
  };
}
github SpankChain / spankbank / test / spank.js View on Github external
payload = await receipt.logs.map( log => {
              if (log.address == spankbank.address) {
                  const topics = (log.topics.length > 1) ? log.topics.slice(1) : []
                  return abi.decodeLog(inputs, log.data, topics)
              }
          })
      }
github citahub / cita-sdk-js / packages / cita-sdk / src / utils / parsers.ts View on Github external
export const LogParser = (log: Log | string, abi: any) => {
  if (typeof log === 'string') return log
  if (!abi) throw new Error('ABI Missed')
  if (abi.length === undefined) throw new Error('ABI must be type of array')
  const topics =
    abi.filter((input: { indexed: boolean }) => input.indexed).length ===
    log.topics.length
      ? log.topics
      : log.topics.slice(1)
  const decodedLogs = ABICoder.decodeLog(abi, log.data || '', topics)
  return { ...log, decodedLogs }
}
github AztecProtocol / AZTEC / packages / extension / src / background / services / EventService / utils / note / helpers / decodeNoteLogs.js View on Github external
const decode = (inputs, rawLog) => {
    const [,
        firstInput,
        secondInput,
    ] = rawLog.topics;

    const decoded = {
        ...abi.decodeLog(inputs, rawLog.data, [
            firstInput,
            secondInput,
        ]),
        blockNumber: rawLog.blockNumber,
    };
    return decoded;
};
github merklejerk / flex-contract / src / coder.js View on Github external
function decodeLogItemArgs(def, log) {
	return normalizeDecodedOutput(
		def.inputs,
		abiEncoder.decodeLog(
			def.inputs,
			log.data,
			log.topics.slice(1)));
}
github trufflesuite / truffle / packages / contract / lib / utils / index.js View on Github external
.map(log => {
        const logABI = constructor.events[log.topics[0]];

        if (logABI == null) return null;

        const copy = Utils.merge({}, log);

        copy.event = logABI.name;
        copy.topics = logABI.anonymous ? copy.topics : copy.topics.slice(1);

        if (copy.data === "0x") copy.data = "";

        let logArgs;
        try {
          logArgs = abi.decodeLog(logABI.inputs, copy.data, copy.topics);
          copy.args = reformat.numbers.call(
            constructor,
            logArgs,
            logABI.inputs
          );
        } catch (_) {
          return null;
        }

        delete copy.data;
        delete copy.topics;

        return copy;
      })
      .filter(log => log != null);
github trufflesuite / truffle / packages / tezos-contract / lib / utils.js View on Github external
if (logABI == null) {
          return null;
        }

        const copy = Utils.merge({}, log);

        copy.event = logABI.name;
        copy.topics = logABI.anonymous ? copy.topics : copy.topics.slice(1);

        if (copy.data === "0x") {
          copy.data = "";
        }

        let logArgs;
        try {
          logArgs = abi.decodeLog(logABI.inputs, copy.data, copy.topics);
        } catch (_) {
          return null;
        }
        copy.args = reformat.numbers.call(constructor, logArgs, logABI.inputs);

        delete copy.data;
        delete copy.topics;

        return copy;
      })
      .filter(log => log != null);
github citahub / cita-sdk-js / packages / cita-sdk / lib / utils / parsers.js View on Github external
exports.LogParser = (log, abi) => {
    if (typeof log === 'string')
        return log;
    if (!abi)
        throw new Error('ABI Missed');
    const decodedLogs = ABICoder.decodeLog(abi, log.data || '', log.topics || []);
    return Object.assign({}, log, { decodedLogs });
};
github aragon / dao-templates / shared / helpers / decodeEvents.js View on Github external
return eventLogs.map(log => {
    log.event = eventAbi.name
    log.args = abi.decodeLog(eventAbi.inputs, log.data, log.topics.slice(1))
    return log
  })
}
github celo-org / celo-monorepo / packages / contractkit / src / explorer / log-explorer.ts View on Github external
tryParseLog(log: Log): null | EventLog {
    if (log.topics.length === 0) {
      return null
    }

    const contractMapping = this.addressMapping.get(log.address)
    if (contractMapping == null) {
      return null
    }
    const logSignature = log.topics[0]
    const matchedAbi = contractMapping.logMapping.get(logSignature)
    if (matchedAbi == null) {
      return null
    }

    const returnValues = abi.decodeLog(matchedAbi.inputs || [], log.data || '', log.topics.slice(1))
    delete (returnValues as any).__length__
    Object.keys(returnValues).forEach((key) => {
      if (Number.parseInt(key, 10) >= 0) {
        delete (returnValues as any)[key]
      }
    })

    const logEvent: EventLog & { signature: string } = {
      address: log.address,
      blockHash: log.blockHash,
      blockNumber: log.blockNumber,
      logIndex: log.logIndex,
      transactionIndex: log.transactionIndex,
      transactionHash: log.transactionHash,
      returnValues,
      event: matchedAbi.name!,