Initial Commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.24;
|
||||
|
||||
contract SimpleStorage {
|
||||
// boolean, uint, int, address, bytes
|
||||
address myAddress = 0xc9445E993dAeA4bA3F1FE1080F0F6f8c46b4d967;
|
||||
uint256 public myNumber = 123; // With Getter, Retrieval Need Gas
|
||||
string myText = "Hello World";
|
||||
//int256 favoriteInt = -5;
|
||||
//bytes32 favoriteBytes = "cat";
|
||||
uint256 myDefaultZero; // Initialize default to 0
|
||||
|
||||
// Paid
|
||||
function storeMyNumber(uint256 _favariteNumber) public virtual {
|
||||
myNumber = _favariteNumber;
|
||||
//retrieve();
|
||||
}
|
||||
|
||||
/*
|
||||
view - for retrieve variable data (Free)
|
||||
pure - for calculation (Free)
|
||||
Free function will cost $ if call in Paid function
|
||||
*/
|
||||
function viewMyNumber() public view returns (uint256) {
|
||||
return myNumber;
|
||||
}
|
||||
|
||||
function pureCalculation() public pure returns (uint256) {
|
||||
return ((1 + 555) * 22) / 88;
|
||||
}
|
||||
|
||||
// Custom People Object
|
||||
struct People {
|
||||
uint256 favoriteNumber;
|
||||
string name;
|
||||
}
|
||||
|
||||
People public personJohn = People({favoriteNumber: 2, name: "John"});
|
||||
|
||||
// Array Variable
|
||||
People[] public people;
|
||||
|
||||
function addNewPerson2(
|
||||
string memory _name,
|
||||
uint256 _favoriteNumber
|
||||
) public {
|
||||
//People memory newPerson = People(_favoriteNumber, _name);
|
||||
people.push(People(_favoriteNumber, _name));
|
||||
nameToFavoriteNumber[_name] = _favoriteNumber;
|
||||
}
|
||||
|
||||
/*
|
||||
calldata - tmp data cannot modify
|
||||
memory - tmp dta can modify
|
||||
storage - permanent data can modify
|
||||
*/
|
||||
|
||||
// Mapping - Easy to find data (Like Java HashMap)
|
||||
mapping(string => uint256) public nameToFavoriteNumber;
|
||||
|
||||
/*
|
||||
EVM, Ethereum Virtual Machine
|
||||
Avalanche, Fantom, Polygon
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user