Skip to content

Instantly share code, notes, and snippets.

View Hero-Development's full-sized avatar

Squeebo Hero-Development

View GitHub Profile
@Hero-Development
Hero-Development / web3-mint.js
Last active December 28, 2021 10:06
Minting example using Web3.js, prechecks the transaction for errors
const handleMintClick = async (evt) => {
if( evt && evt.cancelable )
evt.preventDefault();
try{
//usually returns a BN (BigNumber)
const priceBN = await contract.methods.PRICE().call();
const quantityBN = new Web3.utils.BN( `${quantity}` );
const valueBN = priceBN.mul( quantityBN );
@Hero-Development
Hero-Development / ForwardLinkedList_Sorted_Unique.sol
Created May 13, 2022 21:46
ForwardLinkedList_Sorted_Unique.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.0;
/************************
* @author: squeebo_nft *
************************/
import "@openzeppelin/contracts/utils/Strings.sol";
@Hero-Development
Hero-Development / Recovery.sol
Created June 15, 2022 17:33
Simple contract to recover ETH
// SPDX-License-Identifier: BSD-3
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Address.sol";
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
}
@Hero-Development
Hero-Development / SignedData-step1.js
Last active June 30, 2022 05:25
A simple web3 script to generate new accounts and get the private key
//Step 1: Create a signer
const Web3 = require( 'web3' );
const web3 = new Web3();
const account = web3.eth.accounts.create();
console.log( account );
/*
{
@Hero-Development
Hero-Development / SignedData-step2a.sol
Last active June 30, 2022 17:39
The base contract for other contracts that need to receive and verify struct data and its signature
// SPDX-License-Identifier: BSD-3
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
contract Signed is Ownable{
using ECDSA for bytes32;
@Hero-Development
Hero-Development / SignedData2B.sol
Last active July 1, 2022 14:57
Implementation contract receiving struct data and corresponding signature
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import './Signed.sol';
contract SignedData2B is IERC721, Signed{
struct MintParams{
@Hero-Development
Hero-Development / SignedData-step3.js
Last active June 30, 2022 17:47
Hardhat unit test showing how to load the signer's private key, arrange struct data, and sign it
const { assert } = require("hardhat");
const SignedData2B = artifacts.require( 'contracts/SignedData2B.sol' );
const Web3 = hre.Web3;
const accounts = [];
let owner, signedData;
contract( 'Step2b', async function( accts ){
owner = accts.shift();
@Hero-Development
Hero-Development / ENSLookup.sol
Created July 8, 2022 16:38
How to resolve ENS on-chain
interface DefaultReverseResolver{
function name(bytes32 node) external view returns (string memory);
}
interface ENS{
function resolver(bytes32 node) external view returns (address);
}
interface ReverseRegistrar{
function node(address addr) external pure returns (bytes32);
@Hero-Development
Hero-Development / opensea-refresh.php
Last active July 20, 2022 15:25
Automated script to refresh your OpenSea Collection
<?php
error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
$API_KEY = 'xxxxxxxxxxxxxxxx';
$COLLECTION = '0xacfa101ece167f1894150e090d9471aee2dd3041';
$ch = curl_init();
$fd = tmpfile();
for( $i = 0; $i < 7777; $i ){
@Hero-Development
Hero-Development / app.js
Created July 20, 2022 16:37
Getting started with Express.js; you can use this middleware to log all incoming requests. This helps you verify that your server is running and the data it is receiving.
//app.use() adds a middleware
//middleware tries to handle every request
//this middleware is used for logging
app.use(( req, res, next ) => {
let request = req.method.toUpperCase() +' '+ req.url
if( Object.keys( req.query ).length ){
request += '?'+ querystring.stringify( req.query )
}