How to use eth-method-registry - 2 common examples

To help you get started, we’ve selected a few eth-method-registry 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 brave / ethereum-remote-client / ui / app / helpers / transactions.util.js View on Github external
SEND_TOKEN_ACTION_KEY,
  TRANSFER_FROM_ACTION_KEY,
  SIGNATURE_REQUEST_KEY,
  CONTRACT_INTERACTION_KEY,
  CANCEL_ATTEMPT_ACTION_KEY,
} from '../constants/transactions'

import { addCurrencies } from '../conversion-util'

abiDecoder.addABI(abi)

export function getTokenData (data = '') {
  return abiDecoder.decodeMethod(data)
}

const registry = new MethodRegistry({ provider: global.ethereumProvider })

/**
 * Attempts to return the method data from the MethodRegistry library, if the method exists in the
 * registry. Otherwise, returns an empty object.
 * @param {string} data - The hex data (@code txParams.data) of a transaction
 * @returns {Object}
 */
export async function getMethodData (data = '') {
  const prefixedData = ethUtil.addHexPrefix(data)
  const fourBytePrefix = prefixedData.slice(0, 10)
  const sig = await registry.lookup(fourBytePrefix)

  if (!sig) {
    return {}
  }
github brave / ethereum-remote-client / ui / app / helpers / utils / transactions.util.js View on Github external
async function getMethodFrom4Byte (fourBytePrefix) {
  const fourByteResponse = (await fetchWithCache(`https://www.4byte.directory/api/v1/signatures/?hex_signature=${fourBytePrefix}`, {
    referrerPolicy: 'no-referrer-when-downgrade',
    body: null,
    method: 'GET',
    mode: 'cors',
  }))

  if (fourByteResponse.count === 1) {
    return fourByteResponse.results[0].text_signature
  } else {
    return null
  }
}

const registry = new MethodRegistry({ provider: global.ethereumProvider })

/**
 * Attempts to return the method data from the MethodRegistry library, the message registry library and the token abi, in that order of preference
 * @param {string} fourBytePrefix - The prefix from the method code associated with the data
 * @returns {Object}
 */
export async function getMethodDataAsync (fourBytePrefix) {
  try {
    const fourByteSig = getMethodFrom4Byte(fourBytePrefix).catch((e) => {
      log.error(e)
      return null
    })

    let sig = await registry.lookup(fourBytePrefix)

    if (!sig) {

eth-method-registry

A module for getting method signature info from an ethereum method signature.

ISC
Latest version published 3 months ago

Package Health Score

79 / 100
Full package analysis

Popular eth-method-registry functions