Skip to main content
Bounty Ended with 50 reputation awarded by Paul S
edited body
Source Link
Tim Coulter
  • 1k
  • 1
  • 7
  • 9

Do this: You'll need to pull code from web3, and it works best if your frontend is bundled using something like webpack or browserify:

var SolidityCoder = require("web3/lib/solidity/coder.js");
var log = receipt.logs[0];
var data = SolidityCoder.decodeParams(["string", "uint"], log.data.replace("0x", ""));

In this case, we're decoding log data that contains two variables, one a string type and one a uint.

EDIT:

If you have the ABI available, you can detect which event it is related to that ABI:

var SolidityCoder = require("web3/lib/solidity/coder.js");

// You might want to put the following in a loop to handle all logs in this receipt.
var log = receipt.logs[0];
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 = SolidityCoder.decodeParams(event.inputs, log.data.replace("0x", ""));
  // Do something with the data. Depends on the log and what you're using the data for.
}

Do this: You'll need to pull code from web3, and it works best if your frontend is bundled using something like webpack or browserify:

var SolidityCoder = require("web3/lib/solidity/coder.js");
var log = receipt.logs[0];
var data = SolidityCoder.decodeParams(["string", "uint"], log.data.replace("0x", ""));

In this case, we're decoding log data that contains two variables, one a string type and one a uint.

EDIT:

If you have the ABI available, you can detect which event it is related to that ABI:

var SolidityCoder = require("web3/lib/solidity/coder.js");

// You might want to put the following in a loop to handle all logs in this receipt.
var log = receipt.logs[0];
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 = inputs.map(function(input) {return input.type;});
  var data = SolidityCoder.decodeParams(event.inputs, log.data.replace("0x", ""));
  // Do something with the data. Depends on the log and what you're using the data for.
}

Do this: You'll need to pull code from web3, and it works best if your frontend is bundled using something like webpack or browserify:

var SolidityCoder = require("web3/lib/solidity/coder.js");
var log = receipt.logs[0];
var data = SolidityCoder.decodeParams(["string", "uint"], log.data.replace("0x", ""));

In this case, we're decoding log data that contains two variables, one a string type and one a uint.

EDIT:

If you have the ABI available, you can detect which event it is related to that ABI:

var SolidityCoder = require("web3/lib/solidity/coder.js");

// You might want to put the following in a loop to handle all logs in this receipt.
var log = receipt.logs[0];
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 = SolidityCoder.decodeParams(inputs, log.data.replace("0x", ""));
  // Do something with the data. Depends on the log and what you're using the data for.
}
added 868 characters in body
Source Link
Tim Coulter
  • 1k
  • 1
  • 7
  • 9

Do this: You'll need to pull code from web3, and it works best if your frontend is bundled using something like webpack or browserify:

var SolidityCoder = require("web3/lib/solidity/coder.js");
var log = receipt.logs[0];
var data = SolidityCoder.decodeParams(["string", "uint"], log.data.replace("0x", ""));

In this case, we're decoding log data that contains two variables, one a string type and one a uint.

EDIT:

If you have the ABI available, you can detect which event it is related to that ABI:

var SolidityCoder = require("web3/lib/solidity/coder.js");

// You might want to put the following in a loop to handle all logs in this receipt.
var log = receipt.logs[0];
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 = inputs.map(function(input) {return input.type;});
  var data = SolidityCoder.decodeParams(event.inputs, log.data.replace("0x", ""));
  // Do something with the data. Depends on the log and what you're using the data for.
}

Do this: You'll need to pull code from web3, and it works best if your frontend is bundled using something like webpack or browserify:

var SolidityCoder = require("web3/lib/solidity/coder.js");
var log = receipt.logs[0];
var data = SolidityCoder.decodeParams(["string", "uint"], log.data.replace("0x", ""));

In this case, we're decoding log data that contains two variables, one a string type and one a uint.

Do this: You'll need to pull code from web3, and it works best if your frontend is bundled using something like webpack or browserify:

var SolidityCoder = require("web3/lib/solidity/coder.js");
var log = receipt.logs[0];
var data = SolidityCoder.decodeParams(["string", "uint"], log.data.replace("0x", ""));

In this case, we're decoding log data that contains two variables, one a string type and one a uint.

EDIT:

If you have the ABI available, you can detect which event it is related to that ABI:

var SolidityCoder = require("web3/lib/solidity/coder.js");

// You might want to put the following in a loop to handle all logs in this receipt.
var log = receipt.logs[0];
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 = inputs.map(function(input) {return input.type;});
  var data = SolidityCoder.decodeParams(event.inputs, log.data.replace("0x", ""));
  // Do something with the data. Depends on the log and what you're using the data for.
}
Source Link
Tim Coulter
  • 1k
  • 1
  • 7
  • 9

Do this: You'll need to pull code from web3, and it works best if your frontend is bundled using something like webpack or browserify:

var SolidityCoder = require("web3/lib/solidity/coder.js");
var log = receipt.logs[0];
var data = SolidityCoder.decodeParams(["string", "uint"], log.data.replace("0x", ""));

In this case, we're decoding log data that contains two variables, one a string type and one a uint.