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.

67 lines
2.5 KiB

  1. // For Node >= v13 / es module environments
  2. import BlocknativeSdk from 'bnc-sdk'
  3. import WebSocket from 'ws' // only neccessary in server environments
  4. import dotenv from 'dotenv'
  5. dotenv.config()
  6. const API_URL = process.env.API_URL;
  7. import { createAlchemyWeb3 } from "@alch/alchemy-web3"
  8. const web3 = createAlchemyWeb3(API_URL);
  9. import contractABI from './MoonbirdPunks.json' assert { type: 'json' }
  10. // create options object
  11. const options = {
  12. dappId: 'd30463f1-eb29-42b8-8059-e5596e13d0fe',
  13. networkId: 3,
  14. system: 'ethereum', // optional, defaults to ethereum
  15. transactionHandlers: [event => console.log(event.transaction)],
  16. ws: WebSocket, // only neccessary in server environments
  17. name: 'Instance name here', // optional, use when running multiple instances
  18. onerror: (error) => {console.log(error)} //optional, use to catch errors
  19. }
  20. // initialize and connect to the api
  21. const blocknative = new BlocknativeSdk(options)
  22. const contractAddress = "0x7d82a88Efb60Bb83B3f1665757c20D07E5C0f3ED"
  23. const methodName = "ownerMint"
  24. // const methodName = "flipSaleState"
  25. await blocknative.configuration({
  26. scope: contractAddress, // [required] - either 'global' or valid Ethereum address
  27. // filters: [{"contractCall.methodName":methodName}],
  28. abi: contractABI.abi, // [optional] - valid contract ABI
  29. watchAddress: true // [optional] - Whether the server should automatically watch the "scope" value if it is an address
  30. })
  31. // returns a promise that resolves once the configuration has been applied
  32. // or rejects if there was a problem with the configuration
  33. // call with the address of the account that you would like to receive status updates for
  34. const {
  35. emitter, // emitter object to listen for status updates
  36. details // initial account details which are useful for internal tracking: address
  37. } = blocknative.account(contractAddress)
  38. // console.log(`Watching for ${methodName} on ${contractAddress}...`)
  39. console.log(`Watching for all methods on ${contractAddress}...`)
  40. const nftContract = new web3.eth.Contract(contractABI.abi, contractAddress);
  41. // listen to some events
  42. emitter.on('txPool', transaction => {
  43. // emitter.on('txSent', transaction => {
  44. console.log(`Sending ${transaction.value} wei to ${transaction.to}`)
  45. })
  46. // blocknative.unsubscribe(contractAddress)
  47. // emitter.on('txConfirmed', transaction => {
  48. // console.log('Transaction is confirmed!')
  49. // })
  50. // catch every other event that occurs and log it
  51. // emitter.on('all', transaction => {
  52. // console.log(`Transaction event: ${transaction.eventCode}`)
  53. // })
  54. //