Skip to content

Instantly share code, notes, and snippets.

@fassko
Created September 26, 2022 12:46
Show Gist options
  • Save fassko/66a303af50ec8fd7626636103422f088 to your computer and use it in GitHub Desktop.
Save fassko/66a303af50ec8fd7626636103422f088 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
*/
// https://gateway.pinata.cloud/ipfs/Qmcz9FgVWPSfTpiQYn5NFRsAnbupDZ6wQpA3dYB17cRL6G
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 {
require(amount > 0, "Please donate more than 0");
require(bytes(tokenURI).length > 0, "Please set token metadata");
_tokenIds.increment();
// get new identifier so nobody else would get it
uint256 newItemId = _tokenIds.current();
// mint the NFT
_mint(msg.sender, newItemId);
// set token metadata according to ERC721 token standard https://eips.ethereum.org/EIPS/eip-721
_setTokenURI(newItemId, tokenURI);
// keep donated amounts
donated[msg.sender] += amount;
console.log("Token ID", newItemId);
// emit event to notify frontend
emit Donated(newItemId, amount, tokenURI);
}
// get donated amount
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