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.

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