Skip to content

Instantly share code, notes, and snippets.

@kennethhutw
kennethhutw / .deps...github...OpenZeppelin...openzeppelin-contracts...contracts...GSN...Context.sol
Created December 14, 2021 03:13
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.4+commit.c7e474f2.js&optimize=true&runs=200&gist=
pragma solidity ^0.5.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
@kennethhutw
kennethhutw / MetaMaskAccountAndNetworkChanage.js
Created October 21, 2020 18:12
Detecting Metamask account or network change in Javascript using Web3 1.2.4
window.addEventListener("load", function() {
if (window.ethereum) {
// use MetaMask's provider
App.web3 = new Web3(window.ethereum);
window.ethereum.enable(); // get permission to access accounts
// detect Metamask account change
window.ethereum.on('accountsChanged', function (accounts) {
console.log('accountsChanges',accounts);
pragma solidity ^0.5.0;
// METADATA 是每一個token 都有不同的metadata
// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/drafts/Counters.sol";
// ERC721Full
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC721/ERC721Enumerable.sol";
@kennethhutw
kennethhutw / App.js
Created March 8, 2020 17:40 — forked from kevinold/App.js
Left and Right Drawers with React Navigation
import React, { Component } from 'react';
import { Text } from 'react-native';
import { DrawerNavigator } from 'react-navigation';
const ContentScreen = ({ navigation }) => (
<Text>Content Hello World</Text>
);
const LeftDrawerScreen = ({ navigation }) => (
<Text>Left Drawer</Text>
const fs = require("fs")
let BITBOX = require('bitbox-sdk').BITBOX;
let bitbox = new BITBOX();
var mnemonic = bitbox.Mnemonic.generate()
const NETWORK = `mainnet`;
const filetime = new Date().getTime();
console.log("mnemonic",mnemonic);
@kennethhutw
kennethhutw / ECDSA-secp256k1-example.cs
Created June 5, 2019 14:14 — forked from nakov/ECDSA-secp256k1-example.cs
ECDSA with secp256k1 in C# - Generate Keys, Sign, Verify
using System;
using System.Text;
using Nethereum.Hex.HexConvertors.Extensions;
using Nethereum.Signer;
using Nethereum.Util;
using Nethereum.Signer.Crypto;
class ECDSASecp256k1Example
{
static void Main()
import Web3 from 'web3';
if (window.ethereum) {
window.web3 = new Web3(ethereum);
try {
// Request account access if needed
ethereum.enable();
} catch (error) {
// User denied account access...
}
var Web3 = require('web3');
var web3 = new Web3();
var message = "Hello, I am Kenneth!";
console.log("version :", web3.version);
var signature = web3.eth.accounts.sign(message, '0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7');
console.log("signature :", signature);
var ethUtil = require('ethereumjs-util');
var data = 'Login';
var message = ethUtil.toBuffer(data);
var msgHash = ethUtil.hashPersonalMessage(message);
var privateKey = new Buffer('62debf78d596673bce224a85a90da5aecf6e781d9aadcaedd4f65586cfe670d2', "hex")
var sig = ethUtil.ecsign(msgHash, privateKey);
var signature = ethUtil.toBuffer(sig)
@kennethhutw
kennethhutw / recover.sol
Last active July 19, 2021 10:26
recover
const sigUtil = require('eth-sig-util');
var messageHashx = new Buffer(delegationHash)
const msgParams = { data: messageHashx }
const _signature = sigUtil.personalSign(new Buffer(tokenholder.pk, "hex"),msgParams);
console.log("_signature", _signature);
msgParams.sig = _signature
console.log("recovered address ",sigUtil.recoverPersonalSignature(msgParams));
delegatedTransferOperator.methods.recover(delegationHash, _signature).call((error, result) => {