Send transaction
This commit is contained in:
50
send-tx.js
Normal file
50
send-tx.js
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user