Skip to content

Instantly share code, notes, and snippets.

@CQBinh
CQBinh / TestRandom.sol
Last active October 20, 2022 09:28
The random function on solidity, read more in Vietnamese: https://nhatky.dev/2022/10/20/minh-dang-dung-ham-solidity-random-number-nhu-nay
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import "./libs/zeppelin/token/BEP20/IBEP20.sol";
interface ILPToken is IBEP20 {
function getReserves() external view returns (uint, uint);
}
@CQBinh
CQBinh / TheAirdropDistributor.sol
Last active April 27, 2022 04:47
Airdrop contract distributor using ECDSA signature
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import "../libs/fota/MerkelProof.sol";
contract TheAirdropDistributor is EIP712 {
@CQBinh
CQBinh / TheAirdropDistributor.sol
Last active October 25, 2022 03:38
Airdrop contract distributor by merkle tree vs ECDSA signature
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol";
import "../libs/fota/MerkelProof.sol";
contract TheAirdropDistributor is EIP712Upgradeable {
import Web3 from 'web3'
import { whiteList } from './whiteList'
const web3Provider = new Web3.providers.HttpProvider('https://bsc-dataseed1.binance.org:443')
const web3 = new Web3(web3Provider)
const merkleTree = {
leaves: null,
root: null
}
@CQBinh
CQBinh / MessageVerifier.sol
Last active April 22, 2022 06:49
Sign the eip-712 message using privateKey with nodejs
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
contract MessageVerifier is EIP712 {
constructor(string memory _name, string memory _version) EIP712(_name, _version) {
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/yyy.sock mode 660 level yyy
stats timeout 30s
user haproxy
group haproxy
daemon
maxconn 2048
@CQBinh
CQBinh / ethereum-private-key-recoverer.js
Created May 22, 2019 14:03
The snip code to recover ethereum private key when we know the address and some-chars-missed-private-key
const util require('util')
const eUtil = require('ethereumjs-util')
function translate(str = '', list = []) {
for (const i of list) {
str = util.format(str, i)
}
return str
}
import moment from 'moment'
import lodash from 'lodash'
import map from 'apr-map'
import timeFormater from 'moment-duration-format'
import asyncUtil from './util/async'
import util from './util/index'
import ncp from 'copy-paste'
require('colors')
import { User } from '../../models'
import tokenGenerator from '../../utils/token-generator'
import config from '../../configs'
async function signupUser(body) {
let user = await User.create(body)
const tokenData = user.genTokenData()
user = await User.commonUserData(user.toJSON())
user.token = tokenGenerator.generate(tokenData)
user.refreshToken = tokenGenerator.generate(tokenData, { expiresIn: config.refreshTokenLife })
import { User } from '../../models'
import { userLocale } from '../../locales'
import service from './service'
import responseBuilder from '../../utils/response-builder'
import errorUtil from '../../utils/error'
import to from '../../utils/to'
async function show(req, res) {
const [error, user] = await to(User.commonUserData(req.user))
if (error) {