How to use the web3-eth-abi.encodeEventSignature 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 ethereum / web3.js / packages / web3-eth-contract / src / index.js View on Github external
parent: _this,
                            nextMethod: _this.methods[method.name]
                        });
                        _this.methods[method.name] = cascadeFunc;
                    }

                    // definitely add the method based on its signature
                    _this.methods[method.signature] = func;

                    // add method by name
                    _this.methods[funcName] = func;


                // event
                } else if (method.type === 'event') {
                    method.signature = abi.encodeEventSignature(funcName);
                    var event = _this._on.bind(_this, method.signature);

                    // add method only if not already exists
                    if(!_this.events[method.name] || _this.events[method.name].name === 'bound ')
                        _this.events[method.name] = event;

                    // definitely add the method based on its signature
                    _this.events[method.signature] = event;

                    // add event by name
                    _this.events[funcName] = event;
                }


                return method;
            });
github hiddentao / ethereum-event-logs / src / index.js View on Github external
const parsers = filteredAbis.map(thisAbi => {
    const key = JSON.stringify(thisAbi)

    if (!cachedParsers[key]) {
      const { name, inputs } = thisAbi

      // compute event signature hash
      const sig = Abi.encodeEventSignature(
        `${name}(${inputs.map(({ type }) => type).join(',')})`
      )

      cachedParsers[key] = {
        name,
        sig,
        parseArgs: createArgsParser(inputs)
      }
    }

    return cachedParsers[key]
  })
github HAECHI-LABS / vvisp / packages / vvisp-utils / src / parseLogs.js View on Github external
const parsers = filteredAbis.map(thisAbi => {
    const key = JSON.stringify(thisAbi);

    if (!cachedParsers[key]) {
      const { name, inputs } = thisAbi;

      // compute event signature hash
      const sig = Abi.encodeEventSignature(
        `${name}(${inputs.map(({ type }) => type).join(',')})`
      );

      cachedParsers[key] = {
        name,
        sig,
        parseArgs: createArgsParser(inputs)
      };
    }

    return cachedParsers[key];
  });
github melonproject / protocol / tests / utils / metadata.js View on Github external
export const getEventFromReceipt = (receiptEvents, contractName, eventName) => {
  const abi = getABI(contractName);
  const eventAbi = abi.find(e => e.type === 'event' && e.name === eventName);

  for (const receiptEvent of Object.values(receiptEvents)) {
    const rawData = receiptEvent.raw;
    if (rawData.topics[0] === web3EthAbi.encodeEventSignature(eventAbi)) {
      return web3EthAbi.decodeLog(
        eventAbi.inputs,
        rawData.data,
        rawData.topics.slice(1)
      );
    }
  }

  return null;
}
github merklejerk / flex-contract / src / coder.js View on Github external
function encodeLogSignature(def) {
	return abiEncoder.encodeEventSignature(def);
}
github melonproject / protocol / src / Contracts.ts View on Github external
const signatureToEvents = R.map(eventAbi => [
      web3EthAbi.encodeEventSignature(eventAbi),
      eventAbi,
    ])(events);
    return {
github merklejerk / flex-contract / src / coder.js View on Github external
function encodeLogTopicsFilter(def, args=[]) {
	const topicArgs = [];
	assert(def.inputs.length == args.length);
	for (let i = 0; i < args.length; i++) {
		if (def.inputs[i].indexed) {
			if (!_.isNil(args[i]))
				topicArgs.push(encodeParameter(def.inputs[i].type, args[i]));
			else
				topicArgs.push(null);
		}
	}
	return [abiEncoder.encodeEventSignature(def), ...topicArgs];
}
github mesg-foundation / engine / src / triggers / ethereum / contract.js View on Github external
module.exports = trigger => {
  const { eventName, contract } = trigger.connector.ethereumContract || trigger.connector.ethereumToken
  const { chain, address } = contract
  const eventAbi = contract.abi
    .filter(x => x.type === 'event')
    .filter(x => x.name === eventName)[0]

  const encodedEvent = Abi.encodeEventSignature(eventAbi)
  const matchLog = log => (log.topics || []).some(topic => topic === encodedEvent)

  return {
    match: ({ type, blockchain, transaction, block }) => {
      if (type !== 'ETHEREUM') { return false }
      if (blockchain !== chain) { return false }
      if (address.toLowerCase() !== (transaction.to || '').toLowerCase()) { return false }

      if (!transaction.logs) {
        Logger.error('transaction log not valid', { type, blockchain, transaction, block })
      }
      return (transaction.logs || []).some(matchLog)
    },
    normalizeEvent: event => {
      const normalizedEvent = normalizeEvent(event)
      return event.transaction.logs
github aragon / aragon-cli / packages / toolkit / src / kernel / kernel.js View on Github external
export function getAppProxyAddressFromReceipt(dao, receipt) {
  const logTopic = web3EthAbi.encodeEventSignature(newAppProxyLogAbi)

  const deployLog = receipt.logs.find(({ topics, address }) => {
    return topics[0] === logTopic && addressesEqual(dao, address)
  })

  if (!deployLog) return

  const log = web3EthAbi.decodeLog(newAppProxyLogAbi.inputs, deployLog.data)
  if (!log.proxy)
    throw new Error(`aragonCLI is out of sync with aragon/os, please report this issue:
Kernel ABI log ${newAppProxyLogName} does not have expected argument 'log'`)
  return log.proxy
}