Created
January 12, 2020 05:50
-
-
Save shahzaintariq/da2431e61f6bc04de98242aa25d2b199 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.5.12+commit.7709ece9.js&optimize=false&gist=
This file contains 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.5.0; | |
interface IAbsCal{ | |
function add(uint _a,uint _b) external returns(uint); | |
function sub(uint _a,uint _b) external returns(uint); | |
function mul(uint _a,uint _b) external returns(uint); | |
function div(uint _a,uint _b) external returns(uint); | |
} | |
contract simplecal is IAbsCal{ | |
function add(uint _a,uint _b) public returns(uint){ | |
return _a + _b; | |
} | |
function sub(uint _a,uint _b) public returns(uint){ | |
return _a - _b; | |
} | |
function mul(uint _a,uint _b) public returns(uint){ | |
return _a * _b; | |
} | |
function div(uint _a,uint _b) public returns(uint){ | |
return _a /_b; | |
} | |
} | |
contract SciCal is simplecal{ | |
function SQRT(uint _a) public pure returns(uint){ | |
return _a**1/2; | |
} | |
function POW(uint _value,uint _power) public pure returns(uint){ | |
return _value**_power; | |
} | |
} | |
contract measure is simplecal{ | |
string measurment = "1 kg grams conversion"; | |
function measurements(uint _kg) public view returns(uint,string memory){ | |
return (_kg*1000 , measurment); | |
} | |
} | |
contract client { | |
function kuchkar() public returns(uint,uint,uint,uint,uint,uint){ | |
SciCal sci = new SciCal(); | |
return( | |
sci.add(0,1), | |
sci.sub(1,1), | |
sci.mul(12,12), | |
sci.div(10,18), | |
sci.SQRT(12), | |
sci.POW(12,12) | |
); | |
} | |
function dobarakuchkaro() public returns(uint,string memory){ | |
measure mes = new measure(); | |
return mes.measurements(2); | |
} | |
} |
This file contains 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.5.11; | |
contract class{ | |
struct bank { | |
string name; | |
uint age; | |
bool ispaid; | |
} | |
bank hbl; | |
function addData(string memory name,uint age,bool ispaid) public returns(string memory){ | |
hbl = bank(name,age,ispaid); | |
} | |
function getdata() public view returns(string memory,uint,bool){ | |
return (hbl.name,hbl.age,hbl.ispaid); | |
} | |
} |
This file contains 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.5.11; | |
contract piaic{ | |
mapping(string => string) studentRecords; | |
function sdetMappingData(string memory key,string memory value ) public { | |
studentRecords[key] = value; | |
} | |
function showdata(string memory key) public view returns(string memory){ | |
return studentRecords[key]; | |
} | |
} |
This file contains 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.22 <0.6.0; | |
contract Ballot { | |
struct Voter { | |
uint weight; | |
bool voted; | |
uint8 vote; | |
address delegate; | |
} | |
struct Proposal { | |
uint voteCount; | |
} | |
address chairperson; | |
mapping(address => Voter) voters; | |
Proposal[] proposals; | |
/// Create a new ballot with $(_numProposals) different proposals. | |
constructor(uint8 _numProposals) public { | |
chairperson = msg.sender; | |
voters[chairperson].weight = 1; | |
proposals.length = _numProposals; | |
} | |
/// Give $(toVoter) the right to vote on this ballot. | |
/// May only be called by $(chairperson). | |
function giveRightToVote(address toVoter) public { | |
if (msg.sender != chairperson || voters[toVoter].voted) return; | |
voters[toVoter].weight = 1; | |
} | |
/// Delegate your vote to the voter $(to). | |
function delegate(address to) public { | |
Voter storage sender = voters[msg.sender]; // assigns reference | |
if (sender.voted) return; | |
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) | |
to = voters[to].delegate; | |
if (to == msg.sender) return; | |
sender.voted = true; | |
sender.delegate = to; | |
Voter storage delegateTo = voters[to]; | |
if (delegateTo.voted) | |
proposals[delegateTo.vote].voteCount += sender.weight; | |
else | |
delegateTo.weight += sender.weight; | |
} | |
/// Give a single vote to proposal $(toProposal). | |
function vote(uint8 toProposal) public { | |
Voter storage sender = voters[msg.sender]; | |
if (sender.voted || toProposal >= proposals.length) return; | |
sender.voted = true; | |
sender.vote = toProposal; | |
proposals[toProposal].voteCount += sender.weight; | |
} | |
function winningProposal() public view returns (uint8 _winningProposal) { | |
uint256 winningVoteCount = 0; | |
for (uint8 prop = 0; prop < proposals.length; prop++) | |
if (proposals[prop].voteCount > winningVoteCount) { | |
winningVoteCount = proposals[prop].voteCount; | |
_winningProposal = prop; | |
} | |
} | |
} |
This file contains 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.5.11; | |
contract student{ | |
enum class {onsite,online} | |
enum gender {male,female} | |
struct studentData{ | |
string name; | |
uint rollNum; | |
bool hasDegree; | |
gender myGender; | |
class myClass; | |
} | |
mapping(uint => studentData) students; | |
address payable private myAddress = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c; | |
function setAddress(address payable add) public { | |
myAddress = add; | |
} | |
function getbalane() public view returns(uint){ | |
return myAddress.balance; | |
} | |
function getAddress() public view returns(address){ | |
return myAddress; | |
} | |
function enroll(string memory yourName, uint RollNum, bool yourDegree, gender yourgender, class yourclass ) public payable returns(string memory){ | |
require(msg.value >= 2 ether); | |
myAddress.transfer(msg.value); | |
studentData memory ssdata = studentData(yourName,RollNum,yourDegree,yourgender,yourclass); | |
students[RollNum] = ssdata; | |
} | |
function getStudentsData(uint RollNum)public view returns(string memory,uint,bool,gender,class){ | |
return (students[RollNum].name,students[RollNum].rollNum,students[RollNum].hasDegree,students[RollNum].myGender,students[RollNum].myClass); | |
} | |
} |
This file contains 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.5.0; | |
interface Ibank{ | |
function deposite() payable external; | |
function withdrwal(uint amount) payable external returns(address); | |
function checkbalance() external view returns(uint); | |
} | |
contract Bank is Ibank { | |
uint8 private totalAccounts; | |
uint private totalBalance; | |
event Deposite(address, uint); | |
event Withdrwal(address, uint); | |
address payable private owner = msg.sender; | |
mapping (address => uint) private balances; | |
modifier ownerOnly() { | |
require (owner == msg.sender); | |
_; | |
} | |
constructor() public payable { | |
require(msg.value >= 50 ether); | |
balances[owner] = msg.value; | |
owner = msg.sender; | |
} | |
function deposite() payable public { | |
require(msg.value > 0); | |
if(totalAccounts < 5){ | |
balances[msg.sender] += msg.value + 10 ether; | |
totalBalance += msg.value + 10 ether; | |
}else { | |
balances[msg.sender] += msg.value; | |
totalBalance += msg.value; | |
} | |
totalAccounts++; | |
emit Deposite(msg.sender, msg.value); | |
} | |
function withdrwal(uint _amount) payable public returns(address){ | |
// to convert wei(_amount) into ether | |
uint amount = _amount * 1000000000000000000; | |
if(amount <= balances[msg.sender]){ | |
balances[msg.sender] -= amount; | |
msg.sender.transfer(amount); | |
} | |
emit Withdrwal(msg.sender, amount); | |
return msg.sender; | |
} | |
function checkbalance() public view returns(uint) { | |
return balances[msg.sender]; | |
} | |
//only owner can invoke | |
function totaldeposite() ownerOnly() view public returns(uint){ | |
return totalBalance; | |
} | |
//only owner can invoke | |
function noOfAccounts()ownerOnly() public view returns(uint){ | |
return totalAccounts; | |
} | |
//only owner can invoke | |
function closeBank() ownerOnly() public{ | |
selfdestruct(owner); | |
} | |
} | |
This file contains 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.5.11; | |
contract student{ | |
enum class {onsite,online} | |
event generateVoucher(uint rollNum,string name); | |
struct studentData{ | |
string name; | |
uint rollNum; | |
class myClass; | |
} | |
mapping(uint => studentData) students; | |
uint numberOfstudents; | |
address payable private myAddress = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c; | |
function setAddress(address payable add) public { | |
myAddress = add; | |
} | |
function getbalane() public view returns(uint){ | |
return myAddress.balance; | |
} | |
function getAddress() public view returns(address){ | |
return myAddress; | |
} | |
modifier onlyOnsite(class classes ){ | |
if(classes == class.onsite){ | |
_; | |
} | |
} | |
function enroll(string memory yourName, uint RollNum,class myClass) onlyOnsite(class.onsite) public payable returns(string memory){ | |
require(msg.value >= 2 ether); | |
myAddress.transfer(msg.value); | |
//studentData memory ssdata = | |
emit generateVoucher(RollNum,yourName); | |
students[RollNum] = studentData(yourName,RollNum,myClass); | |
} | |
function eventAslogging() | |
function getStudentsData(uint RollNum)public view returns(string memory,uint,class){ | |
return ( | |
students[RollNum].name, | |
students[RollNum].rollNum, | |
students[RollNum].myClass | |
); | |
} | |
} |
This file contains 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.5.0; | |
contract Rule3{ | |
//value type on storage | |
uint a = 20; | |
uint[2] public stateAr = [uint(1),2]; | |
mapping (int =>string) public stateS; | |
function doSomething(uint _a, uint _b) public { | |
//value type on memory | |
uint b = 20; | |
uint[2] memory localAr = stateAr; | |
localAr[0] = 6; | |
mapping (int =>string) storage strings = stateS; | |
} | |
function doSomething1(uint _a, uint _b) public pure returns(uint,uint,uint,uint) { | |
uint[2] memory localAr1 = [uint(3),4]; | |
uint[2] memory localAr2 = localAr1;//by reference copy | |
localAr2[0] = 5; | |
return (localAr1[0],localAr1[1],localAr2[0],localAr2[1]); | |
} | |
} |
This file contains 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
//classcode.sol | |
pragma solidity ^0.5.0; | |
import "new.sol"; | |
contract Client{ | |
address[] public addArr; | |
function createNew(uint8 _givevalue) public returns(address){ | |
New newcontract = new New(); | |
newcontract.doSomething(_givevalue); | |
addArr.push(address(newcontract)); | |
return (address(newcontract)); | |
} | |
function callfun(uint8 _value) public returns(int){ | |
New getcontract = New(addArr[_value]); | |
return getcontract.a(); | |
} | |
} |
This file contains 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.5.9; | |
contract Hello { | |
uint public item = 4; | |
uint public item1 = 1; | |
constructor(uint _a, uint _b) public { | |
item = _a; | |
item1 = _b; | |
} | |
function getvalue() public view returns(uint){ | |
return item; | |
} | |
} | |
contract client { | |
function working() public returns(uint){ | |
Hello h1 = new Hello(12,123); | |
return h1.getvalue(); | |
} | |
} |
This file contains 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.5.11; | |
contract helloWorld { | |
function HelloWorld () public returns(string memory) { | |
string memory greeting = "helloWorld"; | |
return greeting; | |
} | |
} |
This file contains 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.5.0; | |
interface IAbsCal{ | |
function add(uint _a,uint _b) external returns(uint); | |
function sub(uint _a,uint _b) external returns(uint); | |
function mul(uint _a,uint _b) external returns(uint); | |
function div(uint _a,uint _b) external returns(uint); | |
} | |
contract simplecal is IAbsCal{ | |
function add(uint _a,uint _b) public returns(uint){ | |
return _a + _b; | |
} | |
function sub(uint _a,uint _b) public returns(uint){ | |
return _a - _b; | |
} | |
function mul(uint _a,uint _b) public returns(uint){ | |
return _a * _b; | |
} | |
function div(uint _a,uint _b) public returns(uint){ | |
return _a /_b; | |
} | |
} | |
contract SciCal is simplecal{ | |
function SQRT(uint _a) public pure returns(uint){ | |
return _a**1/2; | |
} | |
function POW(uint _value,uint _power) public pure returns(uint){ | |
return _value**_power; | |
} | |
} | |
contract measure is simplecal{ | |
string measurment = "1 kg grams conversion"; | |
function measurements(uint _kg) public view returns(uint,string memory){ | |
return (_kg*1000 , measurment); | |
} | |
} | |
contract client { | |
function kuchkar() public returns(uint,uint,uint,uint,uint,uint){ | |
SciCal sci = new SciCal(); | |
return( | |
sci.add(0,1), | |
sci.sub(1,1), | |
sci.mul(12,12), | |
sci.div(10,18), | |
sci.SQRT(12), | |
sci.POW(12,12) | |
); | |
} | |
function dobarakuchkaro() public returns(uint,string memory){ | |
measure mes = new measure(); | |
return mes.measurements(2); | |
} | |
} |
This file contains 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.5.11; | |
contract learning{ | |
struct studentData{ | |
string name; | |
uint age; | |
uint class; | |
string grade; | |
} | |
mapping(uint => studentData) students; | |
function addStudentData(string memory name, uint age, uint class, string memory grade,uint rollno) public { | |
studentData memory addstudent = studentData(name,age,class,grade); | |
students[rollno] = addstudent; | |
} | |
function getStudentData(uint rollno)public view returns(string memory, uint,uint,string memory){ | |
return (students[rollno].name,students[rollno].age,students[rollno].class,students[rollno].grade); | |
} | |
} |
This file contains 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.5.11; | |
contract Mymapping{ | |
enum gender{male,female} | |
struct Student{ | |
string name; | |
gender Mygender; | |
} | |
mapping(uint => Student) Students; | |
function addStudent(uint rollno, string memory name) public { | |
Student memory newstudent = Student(name, gender.male); | |
Students[rollno] = newstudent; | |
} | |
function getstudent(uint rollno)public view returns(string memory){ | |
return Students[rollno].name; | |
} | |
} |
This file contains 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
//mewsol | |
pragma solidity ^0.5.0; | |
contract New{ | |
int public a = 20; | |
function doSomething(uint8 _givenum) public returns(int){ | |
a = a * _givenum; | |
return a; | |
} | |
} |
This file contains 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.5.11; | |
contract numberguess{ | |
uint8 public loserCounter; | |
uint8 public winnerCounter; | |
string public lastWinnerName; | |
uint8[3] numArr; | |
function YourNumber(uint8 _num1, uint8 _num2,uint8 _num3)public{ | |
numArr[0] = _num1; | |
numArr[1] = _num2; | |
numArr[2] = _num3; | |
} | |
function guess(uint8 _yournum,string memory _yourname) public returns(bool){ | |
for(uint8 i=0; i<numArr.length; i++){ | |
if(numArr[i] == _yournum){ | |
lastWinnerName = _yourname; | |
winnerCounter++; | |
return true; | |
} | |
} | |
loserCounter++; | |
return false; | |
} | |
function totalGuess() public view returns(uint){ | |
uint8 guess = loserCounter + winnerCounter; | |
return guess; | |
} | |
} |
This file contains 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.5.11; | |
contract student{ | |
enum class {onsite,online} | |
enum gender {male,female} | |
struct studentData{ | |
string name; | |
uint rollNum; | |
bool hasDegree; | |
gender myGender; | |
class myClass; | |
} | |
mapping(uint => studentData) students; | |
uint numberOfstudents; | |
address payable private myAddress = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c; | |
function setAddress(address payable add) public { | |
myAddress = add; | |
} | |
function getbalane() public view returns(uint){ | |
return myAddress.balance; | |
} | |
function getAddress() public view returns(address){ | |
return myAddress; | |
} | |
function enroll(string memory yourName, uint RollNum, bool yourDegree, gender yourgender, class yourclass ) public payable returns(string memory){ | |
require(msg.value >= 2 ether); | |
myAddress.transfer(msg.value); | |
studentData memory ssdata = studentData(yourName,RollNum,yourDegree,yourgender,yourclass); | |
students[RollNum] = ssdata; | |
numberOfstudents++; | |
} | |
function getStudentsData(uint RollNum)public view returns(string memory,uint,bool,gender,class,uint){ | |
return ( | |
students[RollNum].name, | |
students[RollNum].rollNum, | |
students[RollNum].hasDegree, | |
students[RollNum].myGender, | |
students[RollNum].myClass, | |
numberOfstudents | |
); | |
} | |
} |
This file contains 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.5.0; | |
contract StudentEnrolment{ | |
address payable private myAddress; | |
enum Gender{Male, Female} | |
enum Class{Onsite, Online} | |
struct Student{ | |
string name; | |
uint age; | |
address addr; | |
bool degree; | |
Gender gender; | |
Class class; | |
uint rollNumber; | |
} | |
uint public noOfStudents; | |
mapping(uint => Student)studentData; | |
function setMyAddress(address payable _myAddress)public{ | |
myAddress = _myAddress; | |
} | |
function enrollStudent(string memory _name, uint _age, address _address, bool _haveDegree, Gender _gender, Class _class, uint _rollNumber)public payable{ | |
require(msg.value >= 2 ether); | |
Student memory myStudent = Student(_name, _age, _address, _haveDegree, _gender, _class, _rollNumber); | |
myAddress.transfer(msg.value); | |
studentData[_rollNumber] = myStudent; | |
noOfStudents++; | |
} | |
function getStudentData(uint _rollNumber)public view returns(string memory, uint, address, bool,Gender,Class,uint){ | |
return( | |
studentData[_rollNumber].name, | |
studentData[_rollNumber].age, | |
studentData[_rollNumber].addr, | |
studentData[_rollNumber].degree, | |
studentData[_rollNumber].gender, | |
studentData[_rollNumber].class, | |
studentData[_rollNumber].rollNumber | |
); | |
} | |
function balance()public view returns(uint){ | |
return myAddress.balance; | |
} | |
function hasDegree(uint _rollNumber)public view returns(bool){ | |
return studentData[_rollNumber].degree; | |
} | |
} |
This file contains 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.5.11; | |
contract piaic{ | |
mapping(uint => uint) studentRecords; | |
uint tempno = 123; | |
uint rollno; | |
function sdetMappingData() public { | |
rollno = studentRecords[i]; | |
} | |
function showdata() public view returns(uint){ | |
return rollno; | |
} | |
function getRollNo()public{ | |
for(uint i=0; i<10; i++){ | |
uint rollno = tempno + i; | |
rollno = studentRecords[i]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment