Skip to content

Instantly share code, notes, and snippets.

@ashwinYardi
Created July 13, 2022 10:25
Show Gist options
  • Save ashwinYardi/4a9815b14d9a455297f618081a8d8939 to your computer and use it in GitHub Desktop.
Save ashwinYardi/4a9815b14d9a455297f618081a8d8939 to your computer and use it in GitHub Desktop.
Contract to demo value typed datatypes in solidity
// Solidity program to demonstrate
// value types
pragma solidity ^ 0.8.5;
// Creating a contract
contract DemoValueTypes {
// Initializing Bool variable
bool public boolean;
// Initializing Integer variable
int32 public intVar = -60313;
// Initializing String variable
string public str = "This is the sample string";
// Initializing Byte variable
bytes1 public b = "a";
// Defining an enumerator
enum sampleEnum { first, second, third, defaultValue }
// Defining a function to return values stored in an ENUM
function accessEnum(uint8 index) public pure returns(
sampleEnum) {
if (index == 0) {
return sampleEnum.first;
} else if (index == 1) {
return sampleEnum.second;
} else if (index == 2) {
return sampleEnum.third;
} else {
return sampleEnum.defaultValue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment