How to use abi-decoder - 10 common examples

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 ostdotcom / ost-price-oracle / test / lib / event_decoder.js View on Github external
logger.debug('**** contract address: ' + txReceipt.logs[i].address + ' at log index(' + i + ') in TxHash: ' + txReceipt.transactionHash + '');

        if (!currContractAddrFromReciept) {
          logger.error('**** No contract found for contract address: ' + txReceipt.logs[i].address + ' at log index(' + i + ') in TxHash: ' + txReceipt.transactionHash + '');
          continue;
        }

        // ABI not found
        if (!contractAbi) {
          logger.error("ABI not found for contract: "+contractAddr);
          return;
        }

        relevantLogs.push(txReceipt.logs[i]);
        abiDecoder.addABI(contractAbi);
      }

      if(relevantLogs.length > 0) {
        decodedEvents = abiDecoder.decodeLogs(relevantLogs);
      }

    }

    return this.getFormattedEvents(decodedEvents);
  }
github mosaicdao / mosaic-contracts / test / test_lib / event_decoder.js View on Github external
}
          continue;
        }

        if (!contractAbi) {
          // ABI not found for contract.
          return;
        }

        relevantLogs.push(log);
        abiDecoder.addABI(contractAbi);
      }

      if (relevantLogs.length > 0) {
        decodedEvents = decodedEvents.concat(
          abiDecoder.decodeLogs(relevantLogs)
        );
      }

    }

    return this.getFormattedEvents(decodedEvents);
  }
};
github ostdotcom / ost-price-oracle / test / lib / event_decoder.js View on Github external
logger.error('**** No contract found for contract address: ' + txReceipt.logs[i].address + ' at log index(' + i + ') in TxHash: ' + txReceipt.transactionHash + '');
          continue;
        }

        // ABI not found
        if (!contractAbi) {
          logger.error("ABI not found for contract: "+contractAddr);
          return;
        }

        relevantLogs.push(txReceipt.logs[i]);
        abiDecoder.addABI(contractAbi);
      }

      if(relevantLogs.length > 0) {
        decodedEvents = abiDecoder.decodeLogs(relevantLogs);
      }

    }

    return this.getFormattedEvents(decodedEvents);
  }
github ipfsconsortium / IPFSConsortiumProxy / src / plugins / peepeth / index.js View on Github external
addWatch(options) {
		options.logger.info('addWatch starting Peepeth %s ( from block %s)', metaData.contract, metaData.startblock);
		const contract = new options.web3.eth.Contract(metaData.abi, metaData.contract);

		abiDecoder.addABI(metaData.abi);

		this.options = options;

		this.highestBlock = 0;
		this.eventCount = 0;
		this.pinCount = 0;
		this.picHashes = [];
		this.defaultTtl = 60 * 60 * 24 * 365 * 10; // 10 years

		contract.events.allEvents({
			fromBlock: metaData.startblock,
		}, (error, result) => {
			if (error == null) {
				options.web3.eth.getTransaction(result.transactionHash).then((transaction) => {
					if (transaction.blockNumber > this.highestBlock) {
						this.highestBlock = transaction.blockNumber;
github sponnet / peepin / src / peepin.js View on Github external
.then(transaction => {
        if (transaction.blockNumber > this.highestBlock) {
          this.lastReadBlock = transaction.blockNumber;
        }
        if (!transaction.input) {
          return logger.error(new Error("no transaction input found"));
        }
        let decodedData;
        try {
          decodedData = abiDecoder.decodeMethod(transaction.input);
        } catch (e) {
          return logger.error(e);
        }
        this.eventCount++;

        if (!decodedData || !decodedData.name) {
          return logger.error(new Error("error decoding method"));
        }

        // updateAccount(_ipfsHash string)
        // reply(_ipfsHash string)
        // share(_ipfsHash string)
        // saveBatch(_ipfsHash string)
        // post(_ipfsHash string)
        // createAccount(_name bytes16,_ipfsHash string)
        // tip(_author address,_messageID string,_ownerTip uint256,_ipfsHash string)
github secret-tech / backend-ico-dashboard / src / services / transaction.service.ts View on Github external
getFromToTokenAmountByTxDataAndType(txData: any, type: string): FromToTokenAmount {
    let from = this.web3.utils.toChecksumAddress(txData.from);
    let to = null;
    let tokenAmount = null;

    // direct transfer calls of tokens
    if (type === TOKEN_TRANSFER) {
      abiDecoder.addABI(config.contracts.token.abi);
      const decodedData = abiDecoder.decodeMethod(txData.input);
      if (decodedData.name === 'transfer') {
        to = this.web3.utils.toChecksumAddress(decodedData.params[0].value);
        tokenAmount = this.web3.utils.fromWei(decodedData.params[1].value).toString();
      }
    } else if (txData.to) {
      to = this.web3.utils.toChecksumAddress(txData.to);
    }

    return {
      from,
      to,
      tokenAmount
    };
  }
github SpankChain / chainsaw / output / chainsaw.js View on Github external
logs.push(logsInTheBlock.map(log => {
        log = log.filter(a => this.contractAddresses.indexOf(a.address) >= 0);
        let decodedLogs = abiDecoder.decodeLogs(log);
        // Formating decoded logs to add extra data needed.
        decodedLogs = decodedLogs.map((dLog, i) => {
          return this.constructLogs(dLog, i, log, logsInTheBlock);
        });
        return decodedLogs;
      }).filter(a => a.length > 0));
    }
github cgewecke / eth-gas-reporter / gasStats.js View on Github external
// Report the gas used during initial truffle migration too :
      const networkDeployment = contract.networks[networkId]
      if (networkDeployment && networkDeployment.transactionHash) {
        const code = sync.getCode(networkDeployment.address);
        const hash = sha1(code);
        contractNameFromCodeHash[hash] = name;
        const receipt = sync.getTransactionReceipt(networkDeployment.transactionHash);
        contractInfo.gasData.push(parseInt(receipt.gasUsed, 16));
      }

      abis.push(contract._json.abi)

      // Decode, getMethodIDs
      abiDecoder.addABI(contract._json.abi)
      const methodIDs = abiDecoder.getMethodIDs()

      // Create Method Map;
      Object.keys(methodIDs).forEach(key => {
        const isInterface = contract.unlinked_binary === '0x';
        const isConstant = methodIDs[key].constant
        const isEvent = methodIDs[key].type === 'event'
        const hasName = methodIDs[key].name

        if (hasName && !isConstant && !isEvent && !isInterface) {
          methodMap[name + '_' + key] = {
            key: key,
            contract: name,
            method: methodIDs[key].name,
            gasData: [],
            numberOfCalls: 0
          }
github dharmaprotocol / dharma.js / __test__ / integration / token_api.spec.ts View on Github external
test("should emit log indicating transfer success", async () => {
                    const receipt = await web3Utils.getTransactionReceiptAsync(txHash);
                    const [transferLog] = compact(ABIDecoder.decodeLogs(receipt.logs));

                    expect(transferLog.name).toBe("Transfer");
                });
github dharmaprotocol / dharma.js / __test__ / integration / order_api.spec.ts View on Github external
test("emits log indicating successful fill", async () => {
                const txHash = await orderApi.fillAsync(debtOrder);
                const receipt = await web3Wrapper.getTransactionReceiptAsync(txHash);

                const [debtOrderFilledLog] = _.compact(ABIDecoder.decodeLogs(receipt.logs));

                expect(debtOrderFilledLog.name).toBe("LogDebtOrderFilled");
            });
        });

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