Watch address for transactions
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules/
|
||||
643
MoonbirdPunks.json
Normal file
643
MoonbirdPunks.json
Normal file
File diff suppressed because one or more lines are too long
58
index.js
Normal file
58
index.js
Normal file
@@ -0,0 +1,58 @@
|
||||
// For Node >= v13 / es module environments
|
||||
import BlocknativeSdk from 'bnc-sdk'
|
||||
import Web3 from 'web3'
|
||||
import WebSocket from 'ws' // only neccessary in server environments
|
||||
|
||||
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)
|
||||
|
||||
await blocknative.configuration({
|
||||
scope: "0x7d82a88Efb60Bb83B3f1665757c20D07E5C0f3ED", // [required] - either 'global' or valid Ethereum address
|
||||
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
|
||||
|
||||
// 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
|
||||
const {
|
||||
emitter, // emitter object to listen for status updates
|
||||
details // initial account details which are useful for internal tracking: address
|
||||
} = blocknative.account(address)
|
||||
|
||||
console.log(`Watching for events on ${address}...`)
|
||||
|
||||
// listen to some events
|
||||
emitter.on('txPool', transaction => {
|
||||
console.log(`Sending ${transaction.value} wei to ${transaction.to}`)
|
||||
})
|
||||
|
||||
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}`)
|
||||
})
|
||||
6963
package-lock.json
generated
Normal file
6963
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
package.json
Normal file
16
package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "mint-bot",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bnc-sdk": "^4.2.0",
|
||||
"web3": "^1.7.3"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
Reference in New Issue
Block a user