Created
June 2, 2018 18:09
-
-
Save jigar23/2a51fda5d33a831132717addf4e23480 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.23+commit.124ca40d.js&optimize=false&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract DataTypes { | |
bool myBool = false; | |
// Integers | |
int8 myInt = -128; | |
uint8 myUInt = 255; | |
// array of uint8, bytes | |
string myString; // uint8[] myStringArr | |
// function myFunc(string[] s) { // Not yet implemented | |
function myFunc(string s) { | |
} | |
// Array of bytes | |
byte myValue; | |
//same as -> | |
bytes1 myBytes1; | |
bytes32 myBytes32; | |
// Fixed point number used in financial and floating in geometry | |
// same as integer but with decimal value | |
//fixed8x1 myFixed; // not yet supported | |
enum Action {ADD, REMOVE, UPDATE} | |
Action myAction1 = Action.REMOVE; | |
// explicit conversion not allowed | |
//Action myAction = 1; | |
address myAddress; | |
function assignAddress() { | |
myAddress = msg.sender; | |
//myAddress.balace; | |
myAddress.transfer(10); | |
} | |
// Can add more elements to it | |
uint[] myIntArr = [1,2,3]; | |
function arrFunc() { | |
myIntArr.push(4); | |
myIntArr.length; | |
} | |
function arrFuncPush() { | |
arrFunc(); | |
} | |
// Fixed size | |
uint[10] myFixedArr; | |
// Structs | |
struct Account { | |
uint balance; | |
uint dailyLimit; | |
} | |
Account myAccount; | |
function structFunc() { | |
myAccount.balance = 100; | |
} | |
mapping (address => Account) _account; | |
function mappingFunc() payable { | |
_account[msg.sender].balance += msg.value; | |
} | |
function getBalance() returns (uint) { | |
return _account[msg.sender].balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment