How to use the abi-decoder.getABIs function in abi-decoder

To help you get started, we’ve selected a few abi-decoder 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 theoephraim / ethdevtools / src / devtools / store.js View on Github external
return null;
  }
  const { method, params } = req;
  if (method === 'eth_gasPrice') {
    const cost = new BigNumber(result, 16);
    return {
      wei: cost.toString(10),
      eth: cost.div(1e18).toString(10),
      original: cost.div(1e18).toString(16),
    };
  }
  if (method === 'eth_sendTransaction') return { tx: result };
  if (method === 'eth_call') {
    const contract = store.state.contracts[req.contractAddress];
    if (contract) {
      const abis = AbiDecoder.getABIs();
      const methodSig = req.params[0].data.slice(0, 10);
      const abiMethod = _.find(abis, { signature: methodSig });
      if (abiMethod) {
        const decodedResult = abiCoder.decodeParameters(abiMethod.outputs, result);
        return decodedResult;
      }
    }
  }
  if (method === 'eth_getTransactionReceipt') {
    if (result && result.logs) {
      console.log('HAS RESULT!');
      const annotatedResult = _.cloneDeep(result);
      annotatedResult.decodedLogs = AbiDecoder.decodeLogs(result.logs);
      return annotatedResult;
    }
  }
github theoephraim / ethdevtools / src / devtools / store.js View on Github external
data.annotatedParams = params[0];
  } else if (['eth_call', 'eth_sendTransaction'].includes(method)) {
    const contractAddress = params[0].to;
    const methodSig = params[0].data.slice(0, 10);
    const gasPrice = (params[0].gasPrice || '').slice(0, 10);

    data.contractAddress = contractAddress;
    const contract = store.state.contracts[contractAddress];
    let decodedInput;
    if (contract) {
      decodedInput = AbiDecoder.decodeMethod(methodSig);
      data.callName = `${decodedInput.name}(${decodedInput.params.map((p) => p.type).join(',')})`;
      data.annotatedParams = decodedInput.params.length ? decodedInput.params : null;

      if (data.annotatedParams) {
        const abis = AbiDecoder.getABIs();
        const abiMethod = _.find(abis, { signature: methodSig });
        const decoded = abiCoder.decodeParameters(abiMethod.outputs, params[0].data.slice(10));
        _.each(decoded, (val, key) => {
          if (data.annotatedParams[key]) {
            data.annotatedParams[key].value = val;
          }
        });
      }
    } else {
      data.callName = methodSig;
      data.annotatedParams = methodSig;
    }
  } else {
    console.log(`UNKNOWN METHOD -- ${method}`);
  }
}
github theoephraim / ethdevtools / src / devtools / assets / utils.js View on Github external
eth_call: (args, results, _, contracts) => {
    console.log('eth_call in parser 2');
    let method; let params;
    console.log({ args });
    const contractAddress = args[1][0].to;
    console.log({ contractAddress });
    console.log({ contracts });
    console.log(contracts[contractAddress]);
    if (contracts[contractAddress]) {
      abiDecoder.addABI(contracts[contractAddress].abi);
      const abis = abiDecoder.getABIs();
      console.log({ abis });
      const sig = args[1][0].data.slice(0, 10);
      console.log({ sig });
      method = abis.find((m) => m.signature === args[1][0].data.slice(0, 10));
    }

    console.log({ method });
    if (method) {
      console.log('method', method);
      console.log(abiCoder);
      params = abiCoder.decodeParameters(method.outputs, results.join(''));
      console.log(results);
    }
    console.log({ method }, { params });
    return {
      params,

abi-decoder

Nodejs and Javascript library for decoding data params and events from ethereum transactions"

GPL-3.0
Latest version published 4 years ago

Package Health Score

45 / 100
Full package analysis