Skip to content

Instantly share code, notes, and snippets.

@fassko
Created September 26, 2022 12:14
Show Gist options
  • Save fassko/91161753b75eb9e62d07033771d9a396 to your computer and use it in GitHub Desktop.
Save fassko/91161753b75eb9e62d07033771d9a396 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.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
/**
- NFTs that donated money for Baykar Bayraktar drone to for Ukraine
- Ukraine gets supply
- people feel very good because they have a proof
- in future it could allow for instance travel in Ukraine and visit special places
*/
contract Drone is ERC721URIStorage {
// Increase token identificator
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
// notify frontend about new donation
event Donated(uint256 id, uint256 amount, string tokenURI);
// create the NFT
constructor() ERC721("Drone", "DRN") {}
// hold donated amount
mapping(address => uint256) private donated;
// donate amount and get an NFT back
function donate(uint256 amount, string memory tokenURI) external {
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(msg.sender, newItemId);
donated[msg.sender] += amount;
console.log("Token ID", newItemId);
emit Donated(newItemId, amount, tokenURI);
}
function getDonatedAmount() external view returns(uint256) {
require(donated[msg.sender] > 0, "Not donated yet");
console.log("Donated", donated[msg.sender]);
return donated[msg.sender];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment