Skip to content

Instantly share code, notes, and snippets.

:octocat:
Coding

Miguel Mota miguelmota

:octocat:
Coding
Block or report user

Report or block miguelmota

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@miguelmota
miguelmota / ethers_contract_instance.js
Last active Dec 2, 2019
Web3 ethers.js contract instance
View ethers_contract_instance.js
const contract = new ethers.Contract(address, abi, provider)
const result = await contract.myMethod(data)
// equivalent of
//const contract = await new web3.eth.Contract(abi, address)
//const result = await contract.methods.myMethod(data).call()
@miguelmota
miguelmota / ethers_ecrecover.js
Last active Dec 2, 2019
Web3 ethers.js ecrecover account
View ethers_ecrecover.js
const msgBytes = ethers.utils.arrayify(msgHex)
const sigBytes = ethers.utils.arrayify(sigHex)
const msgSigner = utils.verifyMessage(msgBytes, sigBytes)
// equivalent of:
// const msgSigner = await web3.eth.accounts.recover(msgHex, sigHex)
@miguelmota
miguelmota / pino_trace_caller.js
Created Nov 26, 2019
Node.js pino logger show caller filename and line number
View pino_trace_caller.js
import path from 'path'
import pino from 'pino'
const STACKTRACE_OFFSET = 2
const LINE_OFFSET = 7
const { symbols : { asJsonSym} } = pino
function traceCaller (pinoInstance) {
const get = (target, name) => name === asJsonSym ? asJson : target[name]
@miguelmota
miguelmota / eip1271.js
Created Nov 25, 2019
JavaScript Web3 EIP-1271 (ERC-1271) verifying signature example
View eip1271.js
const Web3 = require('web3')
const provider = new Web3.providers.HttpProvider('https://kovan.infura.io')
const web3 = new Web3(provider)
const eip1271Abi = [
{
"constant": true,
"inputs": [
{
@miguelmota
miguelmota / storageAvailable.js
Created Nov 20, 2019
JavaScript check if localStorage is supported in browser
View storageAvailable.js
export const localStorageAvailable = () => {
return storageAvailable('localStorage')
}
const storageAvailable = (kind = 'localStorage') => {
let storage
try {
storage = window[kind]
let x = '__storage_test__'
storage.setItem(x, x)
@miguelmota
miguelmota / validate_ethereum_address.js
Created Nov 20, 2019
JavaScript validate ethereum public address
View validate_ethereum_address.js
const validAddress = (address) => {
return /^(0x)[0-9a-f]{40}$/i.test(address)
}
@miguelmota
miguelmota / arraybuffer_to_base64.js
Created Nov 20, 2019
JavasScript ArrayBuffer to base64 and base64 to ArrayBuffer
View arraybuffer_to_base64.js
const arrayBufferToBase64 = (arrayBuffer) => {
return window.btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)))
}
@miguelmota
miguelmota / hdwallet.js
Created Nov 15, 2019
JavaScript entropy to seed to hdwallet to private key
View hdwallet.js
const bip39 = require('bip39')
const hdkey = require('ethereumjs-wallet/hdkey')
const entropy = '30d1bd7478be8ec6cc094012bd0b669668ff2d8127e33e279fc8917d1d425ab5'
const seed = await bip39.mnemonicToSeed(bip39.entropyToMnemonic(entropy))
const mnemonic = await bip39.entropyToMnemonic(entropy)
const path = `m/44'/60'/0'/0/0`
const hdwallet = hdkey.fromMasterSeed(seed)
const wallet = hdwallet.derivePath(path).getWallet()
const address = `0x${wallet.getAddress().toString('hex')}`
@miguelmota
miguelmota / entropy_to_mnemonic.js
Last active Dec 3, 2019
JavaScript entropy seed to bip39 mnemonic
View entropy_to_mnemonic.js
const bip39 = require('bip39')
const entropy = '30d1bd7478be8ec6cc094012bd0b669668ff2d8127e33e279fc8917d1d425ab5'
const mnemonic = bip39.entropyToMnemonic(entropy)
console.log(mnemonic) // cotton mistake fringe vapor trophy gloom coral chimney bargain tribe super coast morning nothing afraid wise dilemma diagram vendor carry spike patrol hello physical
@miguelmota
miguelmota / receiver.sh
Last active Nov 15, 2019
Stream data folder contents to netcat
View receiver.sh
nc -l -s 0.0.0.0 -p 1337 | tar xf -
You can’t perform that action at this time.