Skip to content

Instantly share code, notes, and snippets.

View duanescarlett's full-sized avatar

Duane Scarlett duanescarlett

View GitHub Profile
@duanescarlett
duanescarlett / index.js
Last active April 10, 2022 00:37
Send Ether to another wallet
ethers = require('ethers')
require('dotenv').config()
async function main () {
// Connect to an EVM network
const provider = new ethers.providers.JsonRpcProvider(`https://polygon-mainnet.g.alchemy.com/v2/${process.env.RPC_KEY}`)
// Get the gas price
const gasPrice = provider.getGasPrice()
// Create a wallet object from private key
const wallet = new ethers.Wallet(`${process.env.PRIVATE_KEY}`)
@duanescarlett
duanescarlett / main.js
Created March 10, 2022 02:11
Create a new wallet with Ethers JS
ethers = require('ethers')
require('dotenv').config()
const main = async () => {
// Create a wallet
const wallet = ethers.Wallet.createRandom()
console.log('Address: ', wallet.address) // Wallet Address
console.log('Mnemonic: ', wallet.mnemonic.phrase) // Wallet Mnemonic Phrase
console.log('Private Key: ', wallet.privateKey) // Wallet Private Key
@duanescarlett
duanescarlett / main.js
Created March 10, 2022 19:51
Import Wallet from private keys - Ethers
ethers = require('ethers')
require('dotenv').config()
const main = async () => {
// Import a wallet
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY)
console.log('Address: ', wallet.address) // Wallet Address
console.log('Private Key: ', wallet.privateKey) // Wallet Private Key
@duanescarlett
duanescarlett / main.js
Created March 10, 2022 19:57
Import Wallet from Mnemonic - Ethers JS
ethers = require('ethers')
require('dotenv').config()
const main = async () => {
// Import a wallet
const wallet = new ethers.Wallet.fromMnemonic(process.env.MNEMONIC)
console.log('Address: ', wallet.address) // Wallet Address
console.log('Private Key: ', wallet.privateKey) // Wallet Private Key
@duanescarlett
duanescarlett / main.js
Created March 17, 2022 17:39
Convert from number to wei
const Web3 = require('web3')
require('dotenv').config()
const main = async () => {
// Connect to an EVM blockchain
const web3 = new Web3(Web3.givenProvider || process.env.INFURA_URL)
// Convert from a decimal number to a wei number
let amt = web3.utils.toWei('0.1', 'ether')
console.log(amt)
@duanescarlett
duanescarlett / main.js
Created March 21, 2022 16:42
Get ether and erc-20 token balances in a wallet
const ethers = require('ethers')
const { toChecksumAddress } = require('ethereum-checksum-address')
require('dotenv').config()
const main = async () => {
// Connect to an EVM network
const provider = new ethers.providers.JsonRpcProvider(`https://polygon-mainnet.g.alchemy.com/v2/${process.env.RPC_KEY}`)
// Create a wallet
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY)
// Get a signer
@duanescarlett
duanescarlett / main.js
Created March 31, 2022 15:13
This converts from decimal to wei then from wei to decimal
const Web3 = require('web3')
require('dotenv').config()
const main = async () => {
// Connect to a EVM blockchain
const web3 = new Web3(Web3.givenProvider || process.env.INFURA_URL)
// Convert from a decimal number to a wei number
let amt = web3.utils.toWei('0.1', 'ether')
console.log('Convert from a decimal number to a wei number', amt)
@duanescarlett
duanescarlett / main.js
Last active January 5, 2023 23:49
Send ERC-20 tokens to another wallet
const ethers = require('ethers')
const { toChecksumAddress } = require('ethereum-checksum-address')
require('dotenv').config()
const main = async () => {
// Connect to an EVM network
const provider = new ethers.providers.JsonRpcProvider(`https://polygon-mainnet.g.alchemy.com/v2/${process.env.RPC_KEY}`)
// Create a wallet
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY)
// Get a signer
@duanescarlett
duanescarlett / main.js
Last active June 16, 2022 15:36
Get Liquidity Pool address
const ethers = require('ethers')
const { toChecksumAddress } = require('ethereum-checksum-address')
require('dotenv').config()
const main = async () => {
// Connect to an EVM network
const provider = new ethers.providers.JsonRpcProvider(`https://rpc.ankr.com/bsc`)
// Create a Factory contract abi
const IPair = [
@duanescarlett
duanescarlett / DataTypesTutorial.sol
Created February 28, 2023 01:14
This is for a tutorial that teaches datatypes
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.17;
contract VariablesAndDataTypes {
// State Variables
int256 public oneIng = 1;
uint256 public oneUint = 1;
// Local Variable
function getValue() public pure returns(uint256) {