Created
February 20, 2021 20:55
-
-
Save appcypher/6160a6c9c67890885c2be16a9956564f 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.1+commit.c8a2cb62.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
| pragma solidity 0.5.1; | |
| contract ERC20Token { | |
| string public name; | |
| mapping(address => uint256) public balances; | |
| function mint() public { | |
| balances[tx.origin] ++; | |
| } | |
| } | |
| contract Purchase { | |
| address payable public wallet; | |
| address public token; | |
| constructor(address payable _wallet, address _token) public { | |
| wallet = _wallet; | |
| token = _token; | |
| } | |
| function buyToken() public payable { | |
| ERC20Token _token = ERC20Token(address(token)); | |
| _token.mint(); | |
| wallet.transfer(msg.value); | |
| } | |
| } |
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.5.1; | |
| contract MyContract { | |
| uint256 public count = 0; | |
| mapping (uint => Person) public people; | |
| address owner; | |
| modifier onlyOwner() { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| struct Person { | |
| string firstName; | |
| string lastName; | |
| } | |
| constructor() public { | |
| owner = msg.sender; | |
| } | |
| function addPerson(string memory _firstName, string memory _lastName) public onlyOwner { | |
| incrementCount(); | |
| people[count] = Person(_firstName, _lastName); | |
| } | |
| function incrementCount() internal { | |
| count += 1; | |
| } | |
| } |
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.5.1; | |
| contract Token { | |
| mapping (address => uint256) public balances; | |
| address payable wallet; | |
| event Purchase ( | |
| address _buyer, | |
| uint256 _amount | |
| ); | |
| constructor(address payable _wallet) public { | |
| wallet = _wallet; | |
| } | |
| function() external payable { | |
| buyToken(); | |
| } | |
| function buyToken() public payable { | |
| // Buy a token | |
| balances[msg.sender] += 1; | |
| // Send ether to the wallet | |
| wallet.transfer(msg.value); | |
| // Emit event | |
| emit Purchase(msg.sender, 1); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment