How to use the web3-eth-abi.decodeParameters 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 RequestNetwork / Request_SmartContracts / test / synchrone / ethereum / requestEthereumCreateRequest.js View on Github external
var event = null;

	for (var i = 0; i < abi.length; i++) {
	  var item = abi[i];
	  if (item.type != "event") continue;
	  var signature = item.name + "(" + item.inputs.map(function(input) {return input.type;}).join(",") + ")";
	  var hash = web3.sha3(signature);
	  if (hash == log.topics[0]) {
	    event = item;
	    break;
	  }
	}

	if (event != null) {
	  var inputs = event.inputs.map(function(input) {return input.type;});
	  var data = abiUtils.decodeParameters(inputs, log.data.replace("0x", ""));
	  // Do something with the data. Depends on the log and what you're using the data for.
	  return {name:event.name , data:data};
	}
	return null;
}
github kioskprotocol / contracts / test / standardmarket.js View on Github external
const decodeOrderResult = result => {
        // Exclude the indexed parameter "orderID"
        return ABI.decodeParameters(
            [
                { type: "address", name: "market" },
                { type: "bytes32", name: "nonceHash" },
                { type: "uint256[]", name: "DINs" },
                { type: "uint256[]", name: "quantities" }
            ],
            result.receipt.logs[0].data
        );
    };
github RequestNetwork / Request_SmartContracts / test / utils.js View on Github external
var event = null;

  for (var i = 0; i < abi.length; i++) {
    var item = abi[i];
    if (item.type != "event") continue;
    var signature = item.name + "(" + item.inputs.map(function(input) {return input.type;}).join(",") + ")";
    var hash = web3.sha3(signature);
    if (hash == log.topics[0]) {
      event = item;
      break;
    }
  }

  if (event != null) {
    var inputs = event.inputs.filter(function(input) {return !input.indexed;}).map(function(input) {return input.type;});
    var data = abiUtils.decodeParameters(inputs, log.data.replace("0x", ""));
    // Do something with the data. Depends on the log and what you're using the data for.
    return {name:event.name , data:data};
  }
  return null;
}
github aragon / radspec / src / index.js View on Github external
function evaluate (source, call, { userHelpers = {}, ...options } = {}) {
  // Get method ID
  const methodId = call.transaction.data.substr(0, 10)

  // Find method ABI
  const method = call.abi.find((abi) =>
    abi.type === 'function' &&
    methodId === ABI.encodeFunctionSignature(abi))

  // Decode parameters
  const parameterValues = ABI.decodeParameters(
    method.inputs,
    '0x' + call.transaction.data.substr(10)
  )
  const parameters = method.inputs.reduce((parameters, input) =>
    Object.assign(
      parameters, {
        [input.name]: {
          type: input.type,
          value: parameterValues[input.name]
        }
      }
    ), {})

  const availableHelpers = { ...defaultHelpers, ...userHelpers }

  // Get additional options
github ethereum / web3.js / packages / web3-eth-contract / src / index.js View on Github external
Contract.prototype._decodeMethodReturn = function (outputs, returnValues) {
    if (!returnValues) {
        return null;
    }

    returnValues = returnValues.length >= 2 ? returnValues.slice(2) : returnValues;
    var result = abi.decodeParameters(outputs, returnValues);

    if (result.__length__ === 1) {
        return result[0];
    } else {
        delete result.__length__;
        return result;
    }
};
github 0xcert / framework / packages / 0xcert-ethereum-asset-ledger / src / queries / get-supply.ts View on Github external
export default async function(ledger: AssetLedger) {
  const attrs = {
    to: ledger.id,
    data: encodeFunctionCall(abi, []),
  };
  const res = await ledger.provider.send({
    method: 'eth_call',
    params: [attrs, 'latest'],
  });
  return decodeParameters(abi.outputs, res.result)[0];
}
github 0xcert / framework / packages / 0xcert-ethereum-generic-provider / src / procedures / query-contract.ts View on Github external
export function parseResult({ abi }: ContractQueryOptions, { result }: RpcResponse) {
  return decodeParameters(abi.outputs, result);
}
github HAECHI-LABS / vvisp / packages / vvisp-utils / src / parseLogs.js View on Github external
const decodeParameters = (names, types, data) => {
  const ret = {};

  if (names.length && names.length === types.length) {
    const result = Abi.decodeParameters(types, data);

    for (let i = 0; types.length > i; i += 1) {
      if (undefined !== result[i]) {
        ret[names[i]] = result[i];
      }
    }
  }

  return ret;
};
github hiddentao / ethereum-event-logs / src / index.js View on Github external
const decodeParameters = (names, types, data) => {
  const ret = {}

  if (names.length && names.length === types.length) {
    const result = Abi.decodeParameters(types, data)

    for (let i = 0; types.length > i; i += 1) {
      if (undefined !== result[i]) {
        ret[names[i]] = result[i]
      }
    }
  }

  return ret
}