Code Snippets Solidity

Short texts Solidity 🧑‍💻 Code snippets Solidity ✍️ Reading lists Solidity 👀

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.9+commit.e5eed63a.js&optimize=true&runs=1&gist=

// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 uint256) internal _balances; mapping(address => mapping(address => uint256)) internal _allowances; uint256 internal _totalSupply; uint8 internal _decimals; string internal _symbol; string internal _name; address public InformationalFeeContract; uint256 public directSwapFee = 500; struct DirectSwapInfo { address dstoken; uint256 dsmultiplier; } DirectSwapInfo[] public directSwapInfo; mapping(address => uint256) internal _dsmultipliers; constructor( string memory […]

MyEpicGame.sol

// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import “@openzeppelin/contracts/token/ERC721/ERC721.sol”; import “@openzeppelin/contracts/utils/Counters.sol”; import “@openzeppelin/contracts/utils/Strings.sol”; // String encoding libraries import { Base64 } from “./libraries/Base64.sol”; import “hardhat/console.sol”; contract MyEpicGame is ERC721 { struct CharacterAttributes { string name; string imageURI; uint hp; uint attackDamage; } using Counters for Counters.Counter; Counters.Counter private _tokenIds; mapping(uint => CharacterAttributes) public defaultAttributes; mapping(uint256 => […]

Ballot.sol

// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 Voter) public voters; Proposal[] public proposals; constructor(bytes32[] memory proposalNames) { chairperson = msg.sender; voters[chairperson].weight = 1; for (uint i = 0; i < proposalNames.length; i++) { proposals.push(Proposal({ name: proposalNames[i], voteCount: 0 })); } } function giveRightToVote(address voter) public { require( msg.sender == chairperson, "Only chairperson can give right to […]

Activity 6_2

// SPDX-License-Identifier: MIT pragma solidity ^0.6.12; pragma experimental ABIEncoderV2; import “./ownable.sol”; import “./Struct.sol”; interface IFishMarket { function addNewProduct( uint256 _priceInEther, uint256 _minTemperature, uint256 _maxTemperature, string memory _productName ) external returns (bytes32 _productId); function getStock(string memory _productName) external view returns (Stock memory); function addStockQuantity(uint256 _quantity, string memory _productName) external; function removeStockQuantity(uint256 _quantity, string memory _productName) external; […]