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!
Asked
Active
Viewed 528 times
2 Answers
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
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