From b71dd60ab2af516918ba15db2954b4bb17b3d10b Mon Sep 17 00:00:00 2001 From: Kevin Mok Date: Sat, 30 Apr 2022 15:03:48 -0400 Subject: [PATCH] Send transaction --- send-tx.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 send-tx.js diff --git a/send-tx.js b/send-tx.js new file mode 100644 index 0000000..13303ec --- /dev/null +++ b/send-tx.js @@ -0,0 +1,50 @@ +// require('dotenv').config(); +import dotenv from 'dotenv' +dotenv.config() +const API_URL = process.env.API_URL; +// const { createAlchemyWeb3 } = require("@alch/alchemy-web3"); +import { createAlchemyWeb3 } from "@alch/alchemy-web3" +const web3 = createAlchemyWeb3(API_URL); + +// const contract = require("../artifacts/contracts/MyNFT.sol/MyNFT.json"); +import contractABI from './MoonbirdPunks.json' assert { type: 'json' } +// console.log(JSON.stringify(contract.abi)); + +const contractAddress = "0x7d82a88Efb60Bb83B3f1665757c20D07E5C0f3ED"; +const nftContract = new web3.eth.Contract(contractABI.abi, contractAddress); + +async function sendEth() { + const nonce = await web3.eth.getTransactionCount(process.env.PUBLIC_OWNER_KEY, 'latest'); //get latest nonce + + //the transaction + const tx = { + 'from': process.env.PUBLIC_OWNER_KEY, + 'to': process.env.PUBLIC_KEY, + 'value': .01 * Math.pow(10, 18), + 'nonce': nonce, + 'gas': 25000, + 'maxFeePerGasGwei': 30, + // 'maxPriorityFeePerGas': 1000000000, + 'maxPriorityFeePerGasGwei': 1, + }; + + const signedTx = await web3.eth.accounts.signTransaction(tx, process.env.PRIVATE_OWNER_KEY); + console.log(`Sending ${tx.value} from ${tx.from} to ${tx.to}...`) + const transactionReceipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction); + + console.log(`Transaction receipt: ${JSON.stringify(transactionReceipt)}`); +} + +// const fs = require('fs') +// const base64 = require('base-64'); + +// fs.readFile('scripts/geo.json', 'utf8' , (err, data) => { + // if (err) { + // console.error(err) + // return + // } + // // console.log("data:application/json;base64," + base64.encode(data)) + // // mintNFT("data:application/json;base64," + base64.encode(data)) +// }) + +sendEth()