This is a simple Solidity smart contract for storing and retrieving reports on the Ethereum blockchain that we've integrated with our solution in Tatweer Event as we need a secure and publuc non changable place to store our reports. It allows users to add reports with a timestamp and content, and retrieve reports by their ID. The contract emits events whenever a report is added.
The contract is deployed at the following address:
- Contract Address: 0x98e9EF3E3EA80Dd570861201da4EA8B6C8871819
- Add Report: Allows users to add a new report with a timestamp and content.
- Retrieve Report: Allows users to fetch a report's content and timestamp by providing the report's ID.
- Get Report Count: Allows users to fetch the total number of reports stored.
- Event Logging: The contract emits an event whenever a new report is added.
The Report struct stores the details of a report, including:
timestamp: The time when the report was added (in Unix timestamp format).content: The textual content of the report.
An array of Report structs that holds all the stored reports.
This event is emitted when a new report is added. It contains the following parameters:
id: The index of the newly added report in thereportsarray.timestamp: The timestamp when the report was added.content: The content of the newly added report.
Adds a new report with the specified content. The report's timestamp is automatically set to the current block timestamp. Emits the ReportAdded event.
- Input:
_content: The content of the report to be added (string).
- Output: None
Retrieves the report by its ID. Returns the timestamp and content of the report.
- Input:
_id: The ID of the report to retrieve (uint256).
- Output:
timestamp: The timestamp when the report was created.content: The content of the report.
Returns the total number of reports stored in the contract.
- Output:
- The number of reports stored (uint256).
To deploy and interact with this contract, you will need:
- Node.js (v12 or above)
- Hardhat for development and deployment.
- MetaMask or any other Ethereum wallet to interact with the contract.
-
Install dependencies:
npm install
-
Deploy the contract using Hardhat:
npx hardhat run scripts/deploy.js --network <your_network>
-
After deployment, you can interact with the contract via Hardhat or a front-end interface.
Once deployed, you can call the contract's functions to add and retrieve reports.
To add a report, call the addReport function with the content:
await contract.addReport("Report Content");To get a report by its ID, call the getReport function:
const [timestamp, content] = await contract.getReport(0);
console.log("Timestamp:", timestamp);
console.log("Content:", content);To get the number of reports stored:
const count = await contract.getReportCount();
console.log("Total Reports:", count);This project is licensed under the MIT License - see the LICENSE file for details.