Skip to content

Instantly share code, notes, and snippets.

@shobhitic
shobhitic / PreRevealedTokens.sol
Last active December 19, 2022 10:05
Contract to help with Pre reveal metadata for NFT smart contract
View PreRevealedTokens.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts@4.8.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.8.0/access/Ownable.sol";
import "@openzeppelin/contracts@4.8.0/utils/Counters.sol";
contract PreRevealedTokens is ERC721, Ownable {
using Counters for Counters.Counter;
View MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor() ERC20("MyToken", "MTK") {
_mint(msg.sender, 10000000 * 10 ** decimals());
}
}
@shobhitic
shobhitic / index.html
Last active November 20, 2022 16:35
Showcase NFTs from a specific collection with Enumerable module - https://youtu.be/7P2nnpU-HoQ
View index.html
<html>
<head>
<title>Show NFTs</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
</head>
<body>
<div id="root">
</div>
<script>
@shobhitic
shobhitic / DefaultOperatorFilterer.sol
Last active November 14, 2022 10:58
Working version of OpenSea operator filter registry - https://www.youtube.com/watch?v=4spapOTVpNA
View DefaultOperatorFilterer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {OperatorFilterer} from "./OperatorFilterer.sol";
contract DefaultOperatorFilterer is OperatorFilterer {
address constant DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);
constructor() OperatorFilterer(DEFAULT_SUBSCRIPTION, true) {}
}
@shobhitic
shobhitic / Checker.sol
Last active January 15, 2023 04:21
Testing on real blockchain data without tokens - https://www.youtube.com/watch?v=VGZb2orvYJE
View Checker.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract Checker {
function check(address _token, address user) view public returns (uint256) {
return IERC20(_token).balanceOf(user);
@shobhitic
shobhitic / TodoList.sol
Last active October 31, 2022 10:32
TodoList Backend in Solidity - https://www.youtube.com/watch?v=20ktZBancco
View TodoList.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract TodoList {
struct TodoItem {
string task;
bool isCompleted;
}
mapping (uint256 => TodoItem) public list;
@shobhitic
shobhitic / Lock-test.js
Last active October 23, 2022 15:51
Testing smart contract with hardhat - https://www.youtube.com/watch?v=6g5jclcYX88
View Lock-test.js
const {
time,
loadFixture,
} = require("@nomicfoundation/hardhat-network-helpers");
const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs");
const { expect } = require("chai");
describe("Lock", function () {
// We define a fixture to reuse the same setup in every test.
// We use loadFixture to run this setup once, snapshot that state,
@shobhitic
shobhitic / MyToken.sol
Last active October 17, 2022 11:57
Simple Timelock and Vesting Smart Contract - https://www.youtube.com/watch?v=Z8dLFoREfWE
View MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts@4.7.3/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor() ERC20("MyToken", "MTK") {
_mint(msg.sender, 10000 * 10 ** decimals());
}
}
View SimpleFlashLoan.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@aave/core-v3/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract SimpleFlashLoan is FlashLoanSimpleReceiverBase {
using SafeMath for uint;
@shobhitic
shobhitic / ERC4907.sol
Last active December 31, 2022 17:32
Rentable NFT with ERC 4907 on Ethereal, Polygon, and other EVM chains - https://youtu.be/t1ZB0-UwWB0
View ERC4907.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./IERC4907.sol";
contract ERC4907 is ERC721, IERC4907 {
struct UserInfo
{
address user; // address of user role