Estoy usando web3js para obtener detalles de la transacción.
mi código:
const transactionHash = this._req.query.transactionHash; const transaction = await this._web3.eth.getTransactionReceipt(transactionHash); const logs = await transaction.logs; const log = await logs.find(i => i.transactionHash === transactionHash); const topics = await log.topics; const test = await this._web3.eth.abi.decodeParameter('bytes32', topics[0]); const from = await this._web3.eth.abi.decodeParameter('address', topics[1]); const to = await this._web3.eth.abi.decodeParameter('address', topics[2]); const value = await this._web3.eth.abi.decodeParameter('uint256', log.data); const amount = await this._web3.utils.fromWei(value);Pero todavía no tengo el nombre del token de la transacción.
dame algunas sugerencias, gracias
Para obtener el símbolo del token, debe llamar a la función symbol() del contrato del token.
Dado que el evento Transfer fue emitido por el contrato de token, tiene su dirección en la propiedad log.address . Entonces solo necesitas llamar a la función symbol() :
const abiJson = [ {"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"} ]; const contract = new web3.eth.Contract(abiJson, log.address); const symbol = await contract.methods.symbol().call();