Mint punk in same block as flip state
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
.env
|
.env
|
||||||
|
*.txt
|
||||||
|
|||||||
55
index.js
55
index.js
@@ -1,8 +1,13 @@
|
|||||||
// For Node >= v13 / es module environments
|
// For Node >= v13 / es module environments
|
||||||
import BlocknativeSdk from 'bnc-sdk'
|
import BlocknativeSdk from 'bnc-sdk'
|
||||||
import Web3 from 'web3'
|
|
||||||
import WebSocket from 'ws' // only neccessary in server environments
|
import WebSocket from 'ws' // only neccessary in server environments
|
||||||
|
|
||||||
|
import dotenv from 'dotenv'
|
||||||
|
dotenv.config()
|
||||||
|
const API_URL = process.env.API_URL;
|
||||||
|
import { createAlchemyWeb3 } from "@alch/alchemy-web3"
|
||||||
|
const web3 = createAlchemyWeb3(API_URL);
|
||||||
|
|
||||||
import contractABI from './MoonbirdPunks.json' assert { type: 'json' }
|
import contractABI from './MoonbirdPunks.json' assert { type: 'json' }
|
||||||
|
|
||||||
// create options object
|
// create options object
|
||||||
@@ -18,10 +23,13 @@ const options = {
|
|||||||
|
|
||||||
// initialize and connect to the api
|
// initialize and connect to the api
|
||||||
const blocknative = new BlocknativeSdk(options)
|
const blocknative = new BlocknativeSdk(options)
|
||||||
|
const contractAddress = "0x7d82a88Efb60Bb83B3f1665757c20D07E5C0f3ED"
|
||||||
|
// const methodName = "ownerMint"
|
||||||
|
const methodName = "flipSaleState"
|
||||||
|
|
||||||
await blocknative.configuration({
|
await blocknative.configuration({
|
||||||
scope: "0x7d82a88Efb60Bb83B3f1665757c20D07E5C0f3ED", // [required] - either 'global' or valid Ethereum address
|
scope: contractAddress, // [required] - either 'global' or valid Ethereum address
|
||||||
filters: [{"contractCall.methodName":"ownerMint"}],
|
filters: [{"contractCall.methodName":methodName}],
|
||||||
abi: contractABI.abi, // [optional] - valid contract ABI
|
abi: contractABI.abi, // [optional] - valid contract ABI
|
||||||
watchAddress: true // [optional] - Whether the server should automatically watch the "scope" value if it is an address
|
watchAddress: true // [optional] - Whether the server should automatically watch the "scope" value if it is an address
|
||||||
})
|
})
|
||||||
@@ -29,26 +37,48 @@ await blocknative.configuration({
|
|||||||
// returns a promise that resolves once the configuration has been applied
|
// returns a promise that resolves once the configuration has been applied
|
||||||
// or rejects if there was a problem with the configuration
|
// or rejects if there was a problem with the configuration
|
||||||
|
|
||||||
// initialize web3
|
|
||||||
// const web3 = new Web3(window.ethereum)
|
|
||||||
|
|
||||||
// get current account
|
|
||||||
// const accounts = await web3.eth.getAccounts();
|
|
||||||
const address = "0x7d82a88Efb60Bb83B3f1665757c20D07E5C0f3ED"
|
|
||||||
|
|
||||||
// call with the address of the account that you would like to receive status updates for
|
// call with the address of the account that you would like to receive status updates for
|
||||||
const {
|
const {
|
||||||
emitter, // emitter object to listen for status updates
|
emitter, // emitter object to listen for status updates
|
||||||
details // initial account details which are useful for internal tracking: address
|
details // initial account details which are useful for internal tracking: address
|
||||||
} = blocknative.account(address)
|
} = blocknative.account(contractAddress)
|
||||||
|
|
||||||
console.log(`Watching for events on ${address}...`)
|
console.log(`Watching for ${methodName} on ${contractAddress}...`)
|
||||||
|
|
||||||
|
const nftContract = new web3.eth.Contract(contractABI.abi, contractAddress);
|
||||||
|
|
||||||
|
async function mintPunk(maxFee, maxPriorityFee) {
|
||||||
|
const nonce = await web3.eth.getTransactionCount(process.env.PUBLIC_KEY, 'latest'); //get latest nonce
|
||||||
|
|
||||||
|
//the transaction
|
||||||
|
const tx = {
|
||||||
|
'from': process.env.PUBLIC_KEY,
|
||||||
|
'to': contractAddress,
|
||||||
|
'nonce': nonce,
|
||||||
|
'gas': 100000,
|
||||||
|
'maxFeePerGas': maxFee,
|
||||||
|
'maxPriorityFeePerGas': maxPriorityFee,
|
||||||
|
'data': nftContract.methods.mintPunk(1).encodeABI()
|
||||||
|
};
|
||||||
|
|
||||||
|
const signedTx = await web3.eth.accounts.signTransaction(tx, process.env.PRIVATE_KEY);
|
||||||
|
console.log("Minting punk...")
|
||||||
|
const transactionReceipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
|
||||||
|
|
||||||
|
console.log(`Transaction receipt: ${JSON.stringify(transactionReceipt)}`);
|
||||||
|
}
|
||||||
|
|
||||||
// listen to some events
|
// listen to some events
|
||||||
emitter.on('txPool', transaction => {
|
emitter.on('txPool', transaction => {
|
||||||
|
// emitter.on('txSent', transaction => {
|
||||||
console.log(`Sending ${transaction.value} wei to ${transaction.to}`)
|
console.log(`Sending ${transaction.value} wei to ${transaction.to}`)
|
||||||
|
blocknative.unsubscribe(contractAddress)
|
||||||
|
mintPunk(transaction.maxFeePerGas,
|
||||||
|
transaction.maxPriorityFeePerGas)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// blocknative.unsubscribe(contractAddress)
|
||||||
|
|
||||||
// emitter.on('txConfirmed', transaction => {
|
// emitter.on('txConfirmed', transaction => {
|
||||||
// console.log('Transaction is confirmed!')
|
// console.log('Transaction is confirmed!')
|
||||||
// })
|
// })
|
||||||
@@ -57,3 +87,4 @@ emitter.on('txPool', transaction => {
|
|||||||
// emitter.on('all', transaction => {
|
// emitter.on('all', transaction => {
|
||||||
// console.log(`Transaction event: ${transaction.eventCode}`)
|
// console.log(`Transaction event: ${transaction.eventCode}`)
|
||||||
// })
|
// })
|
||||||
|
//
|
||||||
|
|||||||
11
mint-nft.js
11
mint-nft.js
@@ -14,19 +14,22 @@ const contractAddress = "0x7d82a88Efb60Bb83B3f1665757c20D07E5C0f3ED";
|
|||||||
const nftContract = new web3.eth.Contract(contractABI.abi, contractAddress);
|
const nftContract = new web3.eth.Contract(contractABI.abi, contractAddress);
|
||||||
|
|
||||||
async function mintOwnerNFT() {
|
async function mintOwnerNFT() {
|
||||||
const nonce = await web3.eth.getTransactionCount(process.env.PUBLIC_KEY, 'latest'); //get latest nonce
|
const nonce = await web3.eth.getTransactionCount(process.env.PUBLIC_OWNER_KEY, 'latest'); //get latest nonce
|
||||||
|
|
||||||
//the transaction
|
//the transaction
|
||||||
const tx = {
|
const tx = {
|
||||||
'from': process.env.PUBLIC_KEY,
|
'from': process.env.PUBLIC_OWNER_KEY,
|
||||||
'to': contractAddress,
|
'to': contractAddress,
|
||||||
'nonce': nonce,
|
'nonce': nonce,
|
||||||
'gas': 100000,
|
'gas': 100000,
|
||||||
'maxPriorityFeePerGas': 1000000000,
|
'maxFeePerGasGwei': 50,
|
||||||
|
// 'maxPriorityFeePerGas': 1000000000,
|
||||||
|
'maxPriorityFeePerGasGwei': 2,
|
||||||
'data': nftContract.methods.ownerMint([process.env.PUBLIC_KEY], 1).encodeABI()
|
'data': nftContract.methods.ownerMint([process.env.PUBLIC_KEY], 1).encodeABI()
|
||||||
};
|
};
|
||||||
|
|
||||||
const signedTx = await web3.eth.accounts.signTransaction(tx, process.env.PRIVATE_KEY);
|
const signedTx = await web3.eth.accounts.signTransaction(tx, process.env.PRIVATE_OWNER_KEY);
|
||||||
|
console.log("Minting punk...")
|
||||||
const transactionReceipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
|
const transactionReceipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
|
||||||
|
|
||||||
console.log(`Transaction receipt: ${JSON.stringify(transactionReceipt)}`);
|
console.log(`Transaction receipt: ${JSON.stringify(transactionReceipt)}`);
|
||||||
|
|||||||
67
watch.js
Normal file
67
watch.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
// For Node >= v13 / es module environments
|
||||||
|
import BlocknativeSdk from 'bnc-sdk'
|
||||||
|
import WebSocket from 'ws' // only neccessary in server environments
|
||||||
|
|
||||||
|
import dotenv from 'dotenv'
|
||||||
|
dotenv.config()
|
||||||
|
const API_URL = process.env.API_URL;
|
||||||
|
import { createAlchemyWeb3 } from "@alch/alchemy-web3"
|
||||||
|
const web3 = createAlchemyWeb3(API_URL);
|
||||||
|
|
||||||
|
import contractABI from './MoonbirdPunks.json' assert { type: 'json' }
|
||||||
|
|
||||||
|
// create options object
|
||||||
|
const options = {
|
||||||
|
dappId: 'd30463f1-eb29-42b8-8059-e5596e13d0fe',
|
||||||
|
networkId: 3,
|
||||||
|
system: 'ethereum', // optional, defaults to ethereum
|
||||||
|
transactionHandlers: [event => console.log(event.transaction)],
|
||||||
|
ws: WebSocket, // only neccessary in server environments
|
||||||
|
name: 'Instance name here', // optional, use when running multiple instances
|
||||||
|
onerror: (error) => {console.log(error)} //optional, use to catch errors
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize and connect to the api
|
||||||
|
const blocknative = new BlocknativeSdk(options)
|
||||||
|
const contractAddress = "0x7d82a88Efb60Bb83B3f1665757c20D07E5C0f3ED"
|
||||||
|
const methodName = "ownerMint"
|
||||||
|
// const methodName = "flipSaleState"
|
||||||
|
|
||||||
|
await blocknative.configuration({
|
||||||
|
scope: contractAddress, // [required] - either 'global' or valid Ethereum address
|
||||||
|
// filters: [{"contractCall.methodName":methodName}],
|
||||||
|
abi: contractABI.abi, // [optional] - valid contract ABI
|
||||||
|
watchAddress: true // [optional] - Whether the server should automatically watch the "scope" value if it is an address
|
||||||
|
})
|
||||||
|
|
||||||
|
// returns a promise that resolves once the configuration has been applied
|
||||||
|
// or rejects if there was a problem with the configuration
|
||||||
|
|
||||||
|
// call with the address of the account that you would like to receive status updates for
|
||||||
|
const {
|
||||||
|
emitter, // emitter object to listen for status updates
|
||||||
|
details // initial account details which are useful for internal tracking: address
|
||||||
|
} = blocknative.account(contractAddress)
|
||||||
|
|
||||||
|
// console.log(`Watching for ${methodName} on ${contractAddress}...`)
|
||||||
|
console.log(`Watching for all methods on ${contractAddress}...`)
|
||||||
|
|
||||||
|
const nftContract = new web3.eth.Contract(contractABI.abi, contractAddress);
|
||||||
|
|
||||||
|
// listen to some events
|
||||||
|
emitter.on('txPool', transaction => {
|
||||||
|
// emitter.on('txSent', transaction => {
|
||||||
|
console.log(`Sending ${transaction.value} wei to ${transaction.to}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
// blocknative.unsubscribe(contractAddress)
|
||||||
|
|
||||||
|
// emitter.on('txConfirmed', transaction => {
|
||||||
|
// console.log('Transaction is confirmed!')
|
||||||
|
// })
|
||||||
|
|
||||||
|
// catch every other event that occurs and log it
|
||||||
|
// emitter.on('all', transaction => {
|
||||||
|
// console.log(`Transaction event: ${transaction.eventCode}`)
|
||||||
|
// })
|
||||||
|
//
|
||||||
Reference in New Issue
Block a user