Training without cash

Here is a simple example of a smart contract written in Solidity, the programming language for the Ethereum blockchain:

pragma solidity ^0.8.0;
 
contract SimpleSmartContract {
    // State variable to store a value
    uint storedValue;
 
    // A function to set the value of the state variable
    function set(uint x) public {
        storedValue = x;
    }
 
    // A function to get the value of the state variable
    function get() public view returns (uint) {
        return storedValue;
    }
}

This is a very basic smart contract, it has two main function set and get.

  • The set function allows to change the value of the storedValue variable and the get function allow to get the value of storedValue variable.

This contract is stored on the blockchain and once it’s deployed it can’t be modified.

To invoke the contract, you will need an Ethereum wallet with some Ether (the cryptocurrency used on the Ethereum network) to pay for the gas costs of the transaction. You can use a software wallet like MetaMask, or a hardware wallet like Trezor, to interact with the contract.

Once you have an Ethereum wallet, you can use a tool like Remix, a browser-based IDE for Solidity, to interact with the contract.

You can deploy the contract by connecting Remix to the Ethereum network and then using the “Deploy” button. Once the contract is deployed, you will be given an address on the Ethereum network where the contract is located, you can use this address to interact with the contract.

To invoke the set function, you can use the “At Address” tab, and call the function by providing the necessary inputs, in this case the value of x, and confirming the transaction in your wallet.

To invoke the get function, you can use the “At Address” tab, and call the function by providing no inputs and confirming the transaction, then you’ll be able to see the stored value.


Generate Smart Contract Templates

https://docs.openzeppelin.com/contracts/4.x/wizard


🌱 Back to Garden

1 item under this folder.