Skip to content

Instantly share code, notes, and snippets.

@flcoder
Created March 6, 2021 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flcoder/c3ef10be22cfe6d401c6cd860eae307d to your computer and use it in GitHub Desktop.
Save flcoder/c3ef10be22cfe6d401c6cd860eae307d 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.0+commit.c7dfd78e.js&optimize=false&runs=200&gist=
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.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC721/ERC721.sol";
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/utils/Counters.sol";
contract GenericNFT is ERC721 {
struct TokenInfo {
uint bonus;
uint rarity;
}
TokenInfo[] tokenInfo;
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("Generic NFT", "NFTG") {}
/*
Creates a token.
IDEAS:
- Could make it payable if we want to charge BNB to create.
- Could have options passed in the params.
- Could have a factory that owns this contract and is the only authority
to create tokens.
*/
function create(address tokenOwner) public returns (uint256) {
_tokenIds.increment();
uint256 id = _tokenIds.current();
_mint(tokenOwner, id);
generateTokenInfo(id);
return id;
}
/*
Generates info specific to this token.
IDEAS:
- Could generate random seed and use it to create properties
*/
function generateTokenInfo(uint256 id) public {
/* pseudo code */
// bytes32 seed = genSeed(id);
// tokenInfo[id].bonus = genBonus(seed);
// tokenInfo[id].rarity = genRarity(seed);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment