Created
March 7, 2021 19:19
-
-
Save bart-antczak/8657a323efa6473177ac1cf17819e3f0 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.17+commit.d19bba13.js&optimize=false&runs=200&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
REMIX EXAMPLE PROJECT | |
Remix example project is present when Remix loads very first time or there are no files existing in the File Explorer. | |
It contains 3 directories: | |
1. 'contracts': Holds three contracts with different complexity level, denoted with number prefix in file name. | |
2. 'scripts': Holds two scripts to deploy a contract. It is explained below. | |
3. 'tests': Contains one test file for 'Ballot' contract with unit tests in Solidity. | |
SCRIPTS | |
The 'scripts' folder contains example async/await scripts for deploying the 'Storage' contract. | |
For the deployment of any other contract, 'contractName' and 'constructorArgs' should be updated (along with other code if required). | |
Scripts have full access to the web3.js and ethers.js libraries. | |
To run a script, right click on file name in the file explorer and click 'Run'. Remember, Solidity file must already be compiled. | |
Output from script will appear in remix terminal. |
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.8.2; | |
contract MyContract { | |
string public myString = "Hello World!"; | |
} |
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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.1; | |
contract SendMoneyExample { | |
uint public balanceReceived; | |
uint public lockedUntil; | |
function receiveMoney() public payable { | |
balanceReceived += msg.value; | |
lockedUntil = block.timestamp + 1 minutes; | |
} | |
function getBalance() public view returns(uint) { | |
return address(this).balance; | |
} | |
function withdrawMoney() public { | |
if(lockedUntil < block.timestamp) { | |
address payable to = payable(msg.sender); | |
to.transfer(getBalance()); | |
} | |
} | |
function withdrawMoneyTo(address payable _to) public { | |
if(lockedUntil < block.timestamp) { | |
_to.transfer(getBalance()); | |
} | |
} | |
} |
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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.5.13; | |
contract StartStopUpdateExample { | |
mapping (uint => bool) public myMapping; | |
mapping (address => bool) public myaddressMapping; | |
function setValue(uint _index) public { | |
myMapping[_index] = true; | |
} | |
function setMyAddressToTrue() public { | |
myaddressMapping[msg.sender] = true; | |
} | |
} |
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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.5.13; | |
contract StartStopUpdateExample { | |
address owner; | |
bool paused; | |
constructor() public { | |
owner = msg.sender; | |
} | |
function sendMoney() public payable { | |
} | |
function setPaused(bool _paused) public { | |
require(msg.sender == owner, "You are not the owner!"); | |
paused = _paused; | |
} | |
function withdrawAllMone(address payable _to) public { | |
require(msg.sender == owner, "You are not the owner!"); | |
require(!paused, "Contract is paused!"); | |
_to.transfer(address(this).balance); | |
} | |
function destroySmartContract(address payable _to) public { | |
require(msg.sender == owner, "You are not the owner!"); | |
selfdestruct(_to); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment