Skip to content

Instantly share code, notes, and snippets.

@cxkoda
Created October 19, 2021 07:25
Show Gist options
  • Save cxkoda/8224936acc7d5bc4954d9c5b2d752a58 to your computer and use it in GitHub Desktop.
Save cxkoda/8224936acc7d5bc4954d9c5b2d752a58 to your computer and use it in GitHub Desktop.
Solidity GetSet Test contract

GetSet Test Contract

A simple test contract that I used to quickly test various web3 signers.

The contract was deployed to

  • Mainnet: 0xA154Dd714abE63F94501791E9F42993984BF1578
  • Rinkeby: 0xebB76cd4f6AbD9954c68AB6FcaF1124F3f931820

Use at will.

The contract's abi:

[{"inputs":[],"name":"get","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"value_","type":"uint8"}],"name":"setFree","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"value_","type":"uint8"}],"name":"setPaid","outputs":[],"stateMutability":"payable","type":"function"}]
// SPDX-License-Identifier: MIT
// Copyright 2021 David Huber (@cxkoda)
pragma solidity >=0.8.0 <0.9.0;
/**
* @notice Simple test contract.
* @dev Possesses an internal state that can be accessed and manipulated.
* @author David Huber (@cxkoda)
*/
contract GetSet {
/**
* @dev The internal state.
*/
uint8 private _value;
/**
* @dev Returns the internal state.
*/
function get() external view returns (uint8) {
return _value;
}
/**
* @dev Changes the internal state. Gas fees have to be paid.
*/
function setFree(uint8 value_) external {
_value = value_;
}
/**
* @dev Changes the internal state. Gas fees have to be paid.
* An arbitrary eth value has to be sent with the transaction that
* will be immediately returned.
*/
function setPaid(uint8 value_) external payable {
// Sends value right back
(bool sent, ) = (msg.sender).call{value: msg.value}("");
require(sent, "Failed to return Ether");
_value = value_;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment