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.

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