0

I would like to know if it's possible to get the log data of a smart contract. The thing is that I need to get the adress, the tokenId and a couple more variables, but I don't know how to get that information once the contract is already deployed. Thank you in advance!

Santiago
  • 3
  • 1
  • What do you exactly mean by "log data"? Are you talking about logged events? Those can be found in the transaction receipt. – phaze Feb 18 '22 at 14:45
  • Let me explain it. When I deploy the contract I emit an event, but I can't access to it directly to get the information. cause I don't know how actually. So I need a way that allows me to deploy the contract and then get the information about it. – Santiago Feb 18 '22 at 17:03
  • I did actually notice that Hardhat has a console.log(..) function, but I think you need to use the Hardhat framework to make the tx calls and be able to view those logs. – Ahmed Ihsan Tawfeeq Feb 19 '22 at 20:31

2 Answers2

0

You can declare variable as public after you get variable data via simple web3 call of that function.

Akshay Tarpara
  • 393
  • 1
  • 12
0

As Akshay has said, you can simply make variables public to read from the contract later, but you can also read events from the transaction receipt.

An example using ethersjs: Test.sol

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;

contract Test { event TestEvent(uint256 data);

constructor() {
    emit TestEvent(123);
}

}

deploy.js

const Test = await ethers.getContractFactory('Test');
let test = await Test.deploy();
test = await test.deployed();
let receipt = await test.deployTransaction.wait();
let events = receipt.events;

let testEvent = events.filter(({event}) => event == 'TestEvent')[0]; console.log(testEvent.args.data);

>> BigNumber { value: "123" }
phaze
  • 1,575
  • 4
  • 12