Basic Smart Contract Example
Solidity smart contracts on IOTA Smart Contracts are compatible with Solidity smart contracts on any other network. Most smart contracts will work directly without any modification. To get a rough indication of what a simple Solidity smart contract looks like, see the example below:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;
contract Counter {
uint private count;
constructor() {
count = 0;
}
function increment() public {
count += 1;
}
function decrement() public {
require(count > 0, "Count is already zero");
count -= 1;
}
function getCount() public view returns (uint) {
return count;
}
}
This contract simply updates a count variable. It has
three entry points:
incrementanddecrement: Two full entry points that can alter the state, i.e. thecount variable.getCount: A view only entry point, which simply renders the currentcountstate.
For more information, please visit the official Solidity documentation.
Deploy a Smart Contract
Deploy a Solidity Smart Contract following our how to Deploy a Smart Contract guide.