Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Counter with Timer Contract

The Counter with Timer Contract is a simple Solidity smart contract that allows you to increment or decrement a counter value and set a timer for the next available action. This contract demonstrates the use of state variables, functions, and time-based operations in Solidity.

Features

  • Increment counter value
  • Decrement counter value
  • Set a timer for the next available action
  • Get the current counter value
  • Get the remaining time until the next action

Prerequisites

  • Solidity compiler (version 0.8.x or later)
  • An Ethereum development environment (e.g., Remix, Truffle, Hardhat)

Contract Deployment

To deploy the CounterWithTimer contract, you'll need to compile the Solidity code and deploy it to an Ethereum network (e.g., local development network, test network, or main net).

Here's an example of how to deploy the contract using Remix:

  1. Open the Remix IDE (https://remix.ethereum.org)
  2. Create a new file and copy the CounterWithTimer.sol contract code into it
  3. Compile the contract by clicking on the "Compile" button
  4. Switch to the "Deploy & Run Transactions" environment
  5. Select the CounterWithTimer contract from the contract dropdown
  6. Click on the "Deploy" button to deploy the contract to the selected network

Contract Usage

Once the contract is deployed, you can interact with it through the Remix IDE or by using a tool like Web3.js or Ethers.js in your application.

Functions

  • increment(): Increments the counter value by 1.
  • decrement(): Decrements the counter value by 1.
  • setTimer(uint256 _delay): Sets a timer for the next available action after the specified delay (in seconds).
  • getCount(): Returns the current counter value.
  • getTimeRemaining(): Returns the remaining time (in seconds) until the next available action.

Example Usage

// Increment the counter
counterWithTimer.increment();

// Decrement the counter
counterWithTimer.decrement();

// Set a timer for 60 seconds
counterWithTimer.setTimer(60);

// Get the current counter value
uint256 currentCount = counterWithTimer.getCount();

// Get the remaining time until the next action
uint256 timeRemaining = counterWithTimer.getTimeRemaining();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages