You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. // require('dotenv').config();
  2. import dotenv from 'dotenv'
  3. dotenv.config()
  4. const API_URL = process.env.API_URL;
  5. // const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
  6. import { createAlchemyWeb3 } from "@alch/alchemy-web3"
  7. const web3 = createAlchemyWeb3(API_URL);
  8. // const contract = require("../artifacts/contracts/MyNFT.sol/MyNFT.json");
  9. import contractABI from './MoonbirdPunks.json' assert { type: 'json' }
  10. // console.log(JSON.stringify(contract.abi));
  11. const contractAddress = "0x90Bc839511e1a8b32e2ba27f37c7632D12E872B6";
  12. const nftContract = new web3.eth.Contract(contractABI.abi, contractAddress);
  13. async function mintOwnerNFT() {
  14. const nonce = await web3.eth.getTransactionCount(process.env.PUBLIC_OWNER_KEY, 'latest'); //get latest nonce
  15. //the transaction
  16. const tx = {
  17. 'from': process.env.PUBLIC_OWNER_KEY,
  18. 'to': contractAddress,
  19. 'nonce': nonce,
  20. 'gas': 100000,
  21. 'maxFeePerGasGwei': 50,
  22. // 'maxPriorityFeePerGas': 1000000000,
  23. 'maxPriorityFeePerGasGwei': 2,
  24. 'data': nftContract.methods.ownerMint([process.env.PUBLIC_KEY], 1).encodeABI()
  25. };
  26. const signedTx = await web3.eth.accounts.signTransaction(tx, process.env.PRIVATE_OWNER_KEY);
  27. console.log("Minting owner punk...")
  28. const transactionReceipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
  29. console.log(`Transaction receipt: ${JSON.stringify(transactionReceipt)}`);
  30. }
  31. async function mintPunk() {
  32. const nonce = await web3.eth.getTransactionCount(process.env.PUBLIC_KEY, 'latest'); //get latest nonce
  33. //the transaction
  34. const tx = {
  35. 'from': process.env.PUBLIC_KEY,
  36. 'to': contractAddress,
  37. 'value': .001 * Math.pow(10, 18) * 2,
  38. 'nonce': nonce,
  39. 'gas': 150000,
  40. 'maxFeePerGasGwei': 40,
  41. // 'maxPriorityFeePerGas': 1000000000,
  42. 'maxPriorityFeePerGasGwei': 1,
  43. 'data': nftContract.methods.mintPunk(2).encodeABI()
  44. };
  45. const signedTx = await web3.eth.accounts.signTransaction(tx, process.env.PRIVATE_KEY);
  46. console.log("Minting punk...")
  47. const transactionReceipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
  48. console.log(`Transaction receipt: ${JSON.stringify(transactionReceipt)}`);
  49. }
  50. // const fs = require('fs')
  51. // const base64 = require('base-64');
  52. // fs.readFile('scripts/geo.json', 'utf8' , (err, data) => {
  53. // if (err) {
  54. // console.error(err)
  55. // return
  56. // }
  57. // // console.log("data:application/json;base64," + base64.encode(data))
  58. // // mintNFT("data:application/json;base64," + base64.encode(data))
  59. // })
  60. mintOwnerNFT()
  61. // mintPunk()