0% found this document useful (0 votes)
72 views1 page

Solidity Basic Code

This contract defines several state variables to store different data types like integers, booleans, addresses. It also defines local and global variables that can be accessed within functions. The state variables are initialized with sample values and their default values if not assigned are also shown. A function doSomething is defined to demonstrate usage of local and global variables.

Uploaded by

Dimitri Molotov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views1 page

Solidity Basic Code

This contract defines several state variables to store different data types like integers, booleans, addresses. It also defines local and global variables that can be accessed within functions. The state variables are initialized with sample values and their default values if not assigned are also shown. A function doSomething is defined to demonstrate usage of local and global variables.

Uploaded by

Dimitri Molotov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Define the compiler version you would be using

pragma solidity ^0.8.10;

// Start by creating a contract named Variables


contract Variables {
/*
******** State variables **********
*/
/*
uint stands for unsigned integer, meaning non negative integers
different sizes are available. Eg
- uint8 ranges from 0 to 2 ** 8 - 1
- uint256 ranges from 0 to 2 ** 256 - 1
`public` means that the variable can be accessed internally
by the contract and can also be read by the external world
*/
uint8 public u8 = 10;
uint public u256 = 600;
uint public u = 1230; // uint is an alias for uint256

/*
Negative numbers are allowed for int types. Eg
- int256 ranges from -2 ** 255 to 2 ** 255 - 1
*/
int public i = -123; // int is same as int256

// address stands for an ethereum address


address public addr = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c;

// bool stands for boolean


bool public defaultBoo1 = false;

// Default values
// Unassigned variables have a default value in Solidity
bool public defaultBoo2; // false
uint public defaultUint; // 0
int public defaultInt; // 0
address public defaultAddr; // 0x0000000000000000000000000000000000000000

function doSomething() public {


/*
******** Local variable **********
*/
uint ui = 456;

/*
******** Global variables **********
*/

/*
block.timestamp tells us whats the timestamp for the current block
msg.sender tells us which address called the doSomething function
*/
uint timestamp = block.timestamp; // Current block timestamp
address sender = msg.sender; // address of the caller
}
}

You might also like