Skip to content

Instantly share code, notes, and snippets.

View KenoLeon's full-sized avatar

Keno Leon KenoLeon

View GitHub Profile
@KenoLeon
KenoLeon / subprocess_examples.py
Created April 22, 2022 00:07
subprocess examples for wifi networs on the mac
import subprocess
# subprocess.run(["networksetup", "-help"])
# subprocess.run(["networksetup", "-listallhardwareports"])
# subprocess.run(["networksetup", "-listpreferredwirelessnetworks", "en0"])
subprocess.run(["airport", "en0", "--scan"])
@KenoLeon
KenoLeon / multiPromiseChain_03.js
Last active April 12, 2022 18:44
multi promise chain async functions await
function callContract(contractAddress) {
return new Promise((resolve) => {
console.log(`Calling Contract with Address ${contractAddress}`)
setTimeout(() => {
resolve({
contractAddress: contractAddress,
balance: '10 ETH'
});
}, 1000);
})
@KenoLeon
KenoLeon / multiPromiseChain_02.js
Last active April 12, 2022 01:31
Multi Primise Chain 02
function callContract(contractAddress) {
return new Promise((resolve) => {
console.log(`Calling Contract with Address ${contractAddress}`)
setTimeout(() => {
resolve({
contractAddress: contractAddress,
balance: '10 ETH'
});
}, 1000);
})
@KenoLeon
KenoLeon / multiPromiseChain_01.js
Created April 12, 2022 01:01
promise chain 01
function callContract(contractAddress) {
return new Promise((resolve) => {
console.log(`Calling Contract with Address ${contractAddress}`)
setTimeout(() => {
resolve({
contractAddress: contractAddress,
balance: '10 ETH'
});
}, 1000);
})
@KenoLeon
KenoLeon / multiPromises.js
Last active April 12, 2022 00:36
multiple Promises no chaining
// NO chaining:
const EVM_OPERATION_01 = new Promise((resolve) => {
setTimeout(() => {
resolve('Done with Operation 01');
}, 600); // timeout of 600ms to simulate the operation
});
const EVM_OPERATION_02 = new Promise((resolve) => {
@KenoLeon
KenoLeon / InfuraDocsFull.js
Created April 12, 2022 00:11
INfura promise example full
const { ethers } = require("ethers");
async function main() {
// Configure the ITX provider using your Infura credentials
const itx = new ethers.providers.InfuraProvider(
process.env.ETHEREUM_NETWORK,
process.env.INFURA_PROJECT_ID
);
// Create a signer instance based on your private key
@KenoLeon
KenoLeon / InfuraDocs.js
Created April 12, 2022 00:03
Infura promise example
async function deposit(signer) {
const tx = await signer.sendTransaction({
// ITX deposit contract (same address for all public Ethereum networks)
to: '0x015C7C7A7D65bbdb117C573007219107BD7486f9',
// Choose how much ether you want to deposit to your ITX gas tank
value: ethers.utils.parseUnits('0.1', 'ether')
})
// Waiting for the transaction to be mined
await tx.wait()
}
@KenoLeon
KenoLeon / hardHat_docs_async_await.js
Created April 9, 2022 00:31
hardhat dosc async await example
async function main() {
// We get the contract to deploy
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, Hardhat!");
await greeter.deployed();
console.log("Greeter deployed to:", greeter.address);
}
@KenoLeon
KenoLeon / async_function.js
Created April 9, 2022 00:10
prototypical async function with await operator
function EVM_OPERATION() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Done with Operation');
// uncomment this and comment the resolve to test the catch block
// reject('Something went wrong');
}, 600);
});
}
@KenoLeon
KenoLeon / MetaMask_docs_promise.js
Created April 8, 2022 19:39
example of promise in the MetaMask API
params: [
{
from: '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
to: '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
gas: '0x76c0', // 30400
gasPrice: '0x9184e72a000', // 10000000000000
value: '0x9184e72a', // 2441406250
data:
'0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675',
},