Skip to content

Instantly share code, notes, and snippets.

@beshup
Created September 28, 2021 20:10
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 beshup/d559311393d68b4416b4b5ead0254759 to your computer and use it in GitHub Desktop.
Save beshup/d559311393d68b4416b4b5ead0254759 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=
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.4;
// @title Admin contract for marketplace. Holds owner-only functions to adjust marketplace fees, parameters, etc.
abstract contract Admin /* Potentially fill in here */ {
// @notice The fee that the admin account takes off every successful marketplace purchase.
// Measured in basis points (hundredths of a percent), where 10000 denotes 100%.
uint256 constant public _feeInBasisPoints = 500;
// @notice The account that receives marketplace fees.
address private _marketplaceWallet;
// @notice A mapping from an NFT contract's address to whether that contract is whitelisted
// to be used by the marketplace.
mapping (address => bool) public nftContractIsWhitelisted;
// @notice A mapping from an ERC20 currency address to whether that contract is whitelisted
// to be used by the marketplace.
mapping (address => bool) public erc20CurrencyIsWhitelisted;
constructor(address marketplaceWallet) {
_marketplaceWallet = marketplaceWallet;
}
// @notice Whitelisting an NFT contract to be used by the marketplace.
function whitelistNFTContract(address nftContract) /* Fill in here */ {
/*
* Fill in here
*/
}
// @notice Whitelisting an ERC20 currency to be used by the marketplace.
// Can only be called by contract deployer.
function whitelistERC20(address erc20Contract) /* Fill in here */ {
/*
* Fill in here
*/
}
// @notice Set the address receiving marketplace fees.
// Can only be called by contract deployer.
function setMarketplaceWallet(address marketplaceWallet) /* Fill in here */ {
/*
* Fill in here
*/
}
}
// SPDX-License-Identifier: MIT
// Implement a buy-only marketplace. The marketplace facilitates the purchase of ERC721 tokens by ERC20 tokens.
// The marketplace lets sellers put up any NFT so long as its NFT contract has been whitelisted by us.
// Sellers specify a desired currency they would like to receive for their listing. This currency must also be one that has been whitelisted by us.
// Buyers will pay with this currency.
// You can assume that all accounts interacting with the Marketplace have approved the Marketplace to move around their ERC20 and ERC721 tokens,
// prior to interacting with the marketplace.
// Do not move the NFT into escrow upon listing. You can assume that the seller has approved the marketplace to transfer their NFT on their behalf, as stated above.
// You are free to implement this however you'd like. This includes using any contract you'd like. We've provided some useful ones in utils (./utils) for easy reference.
// The purpose (by order of importance) is to make a marketplace that
// 1. Is functional
// 2. Is secure
// 3. Considers usage (eg. does it consider edge cases, is it gas efficient, are emergencies de-risked, etc.). You can get creative here!
// We will send you some testnet eth (Ropsten) that you can use to deploy the contract should we get there.
// If time permits, we would like to use the sample contracts (./sample) and a js script to test a listing and purchase on the marketplace.
pragma solidity ^0.8.4;
import "../utils/ReentrancyGuard.sol";
import "./Admin.sol";
import "../utils/ERC20/IERC20.sol";
import "../utils/ERC721/IERC721.sol";
contract Marketplace is Admin /* Potentially fill in here */ {
/*
* Fill in here
*/
/*
* Constructor
*/
function createListing( /* Fill in here */ ) /* Fill in here */ {
/*
* Fill in here
*/
}
function cancelListing( /* Fill in here */ ) /* Fill in here */ {
/*
* Fill in here
*/
}
function buyNFT( /* Fill in here */ ) /* Fill in here */ {
/*
* Fill in here
*/
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "../utils/ERC20/ERC20.sol";
/**
* @title SimpleToken
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
* Note they can later distribute these tokens as they wish using `transfer` and other
* `ERC20` functions.
* Based on https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/examples/SimpleToken.sol
*/
contract SimpleToken is ERC20 {
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
constructor(
uint256 initialSupply
) ERC20("SimpleToken", "ST") {
_mint(msg.sender, initialSupply);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "../utils/ERC721/ERC721.sol";
/**
* @title SimpleNFT
* @dev Very simple ERC721 Token example.
*/
contract SimpleNFT is ERC721 {
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
constructor (address _mintTo)
ERC721("SimpleNFT", "sNFT")
{
super._safeMint(_mintTo, 1);
super._safeMint(_mintTo, 2);
super._safeMint(_mintTo, 3);
}
}
// this line is added to create a gist. Empty file is not allowed.
// this line is added to create a gist. Empty file is not allowed.
// this line is added to create a gist. Empty file is not allowed.
// this line is added to create a gist. Empty file is not allowed.
// this line is added to create a gist. Empty file is not allowed.
// this line is added to create a gist. Empty file is not allowed.
// this line is added to create a gist. Empty file is not allowed.
// this line is added to create a gist. Empty file is not allowed.
// this line is added to create a gist. Empty file is not allowed.
// this line is added to create a gist. Empty file is not allowed.
// this line is added to create a gist. Empty file is not allowed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment