Ethereum Remix

Writing your smart contract

1. Create a "New File" under contracts with name Counter.sol
Copy and paste the code below to Counter.sol file
1
pragma solidity >=0.4.22 <0.8.0;
2
​
3
contract Counter {
4
uint256 private count = 0;
5
uint256 moneyStored = 0;
6
​
7
function incrementCounter() public {
8
count += 1;
9
}
10
function decrementCounter() public {
11
count -= 1;
12
}
13
​
14
function addMoney() payable public {
15
moneyStored += msg.value;
16
}
17
​
18
function getCount() public view returns (uint256) {
19
return count;
20
}
21
​
22
function getMoneyStored() public view returns (uint256){
23
return moneyStored;
24
}
25
}
Copied!

Compiling

2. Compile Counter.sol

Deploying

If you want to deploy the contract to a live network like Harmony Testnet or Mainnet, configure your metamask by adding the required Harmony networks using this guide.
3. Deploy the compiler contract. Select Injected Web3 for deploying to live network like Harmony testnet.
4. Confirm the deploy transaction in metamask and you can find the deployed contract address.
​
​

​

Last modified 4mo ago
Export as PDF
Copy link