How to use @zilliqa-js/subscriptions - 9 common examples

To help you get started, we’ve selected a few @zilliqa-js/subscriptions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Zilliqa / Zilliqa-JavaScript-Library / examples / newTxBlockSubscriptions.js View on Github external
async function test() {
  // first run `python websocket.py` to start websocket server locally
  const zilliqa = new Zilliqa('https://dev-api.zilliqa.com');
  const subscriber = zilliqa.subscriptionBuilder.buildNewBlockSubscriptions(
    'ws://',
  );
  subscriber.emitter.on(StatusType.SUBSCRIBE_NEW_BLOCK, (event) => {
    console.log('get SubscribeNewBlock echo: ', event);
  });

  subscriber.emitter.on(MessageType.NEW_BLOCK, (event) => {
    console.log('get new block: ', event.value.TxBlock.header);
  });

  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
    console.log('get unsubscribe event: ', event);
  });

  subscriber.emitter.on(SocketConnect.CLOSE, (event) => {
    console.log('get socket close: ', event);
  });

  subscriber.emitter.on(SocketConnect.ERROR, (event) => {
    console.log('get socket error: ', event);
  });

  await subscriber.start();
  // await subscriber.stop();
}
github Zilliqa / Zilliqa-JavaScript-Library / examples / newEventLogSubscriptions.js View on Github external
async function test() {
  // first run `python websocket.py` to start websocket server locally
  const zilliqa = new Zilliqa('https://dev-api.zilliqa.com');
  const subscriber = zilliqa.subscriptionBuilder.buildEventLogSubscriptions(
    'ws://',
    {
      addresses: [
        '0x2ce491a0fd9e318b39172258101b7c836da7449b',
        '0x167e3980e04eab1e89ff84523ae8c77e008932dc',
      ],
    },
  );
  subscriber.emitter.on(StatusType.SUBSCRIBE_EVENT_LOG, (event) => {
    console.log('get SubscribeEventLog echo: ', event);
  });
  subscriber.emitter.on(MessageType.EVENT_LOG, (event) => {
    console.log('get new event log: ', JSON.stringify(event));
  });
  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
    console.log('get unsubscribe event: ', event);
  });

  await subscriber.start();
  // await subscriber.stop();
}
github Zilliqa / Zilliqa-JavaScript-Library / examples / newTxBlockSubscriptions.js View on Github external
async function test() {
  // first run `python websocket.py` to start websocket server locally
  const zilliqa = new Zilliqa('https://dev-api.zilliqa.com');
  const subscriber = zilliqa.subscriptionBuilder.buildNewBlockSubscriptions(
    'ws://',
  );
  subscriber.emitter.on(StatusType.SUBSCRIBE_NEW_BLOCK, (event) => {
    console.log('get SubscribeNewBlock echo: ', event);
  });

  subscriber.emitter.on(MessageType.NEW_BLOCK, (event) => {
    console.log('get new block: ', event.value.TxBlock.header);
  });

  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
    console.log('get unsubscribe event: ', event);
  });

  subscriber.emitter.on(SocketConnect.CLOSE, (event) => {
    console.log('get socket close: ', event);
  });

  subscriber.emitter.on(SocketConnect.ERROR, (event) => {
    console.log('get socket error: ', event);
  });

  await subscriber.start();
github Zilliqa / Zilliqa-JavaScript-Library / examples / newEventLogSubscriptions.js View on Github external
async function test() {
  // first run `python websocket.py` to start websocket server locally
  const zilliqa = new Zilliqa('https://dev-api.zilliqa.com');
  const subscriber = zilliqa.subscriptionBuilder.buildEventLogSubscriptions(
    'ws://',
    {
      addresses: [
        '0x2ce491a0fd9e318b39172258101b7c836da7449b',
        '0x167e3980e04eab1e89ff84523ae8c77e008932dc',
      ],
    },
  );
  subscriber.emitter.on(StatusType.SUBSCRIBE_EVENT_LOG, (event) => {
    console.log('get SubscribeEventLog echo: ', event);
  });
  subscriber.emitter.on(MessageType.EVENT_LOG, (event) => {
    console.log('get new event log: ', JSON.stringify(event));
  });
  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
    console.log('get unsubscribe event: ', event);
  });

  await subscriber.start();
  // await subscriber.stop();
}
github Zilliqa / Zilliqa-JavaScript-Library / examples / newTxBlockSubscriptions.js View on Github external
async function test() {
  // first run `python websocket.py` to start websocket server locally
  const zilliqa = new Zilliqa('https://dev-api.zilliqa.com');
  const subscriber = zilliqa.subscriptionBuilder.buildNewBlockSubscriptions(
    'ws://',
  );
  subscriber.emitter.on(StatusType.SUBSCRIBE_NEW_BLOCK, (event) => {
    console.log('get SubscribeNewBlock echo: ', event);
  });

  subscriber.emitter.on(MessageType.NEW_BLOCK, (event) => {
    console.log('get new block: ', event.value.TxBlock.header);
  });

  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
    console.log('get unsubscribe event: ', event);
  });

  subscriber.emitter.on(SocketConnect.CLOSE, (event) => {
    console.log('get socket close: ', event);
  });

  subscriber.emitter.on(SocketConnect.ERROR, (event) => {
github Zilliqa / Zilliqa-JavaScript-Library / examples / newEventLogSubscriptions.js View on Github external
const subscriber = zilliqa.subscriptionBuilder.buildEventLogSubscriptions(
    'ws://',
    {
      addresses: [
        '0x2ce491a0fd9e318b39172258101b7c836da7449b',
        '0x167e3980e04eab1e89ff84523ae8c77e008932dc',
      ],
    },
  );
  subscriber.emitter.on(StatusType.SUBSCRIBE_EVENT_LOG, (event) => {
    console.log('get SubscribeEventLog echo: ', event);
  });
  subscriber.emitter.on(MessageType.EVENT_LOG, (event) => {
    console.log('get new event log: ', JSON.stringify(event));
  });
  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
    console.log('get unsubscribe event: ', event);
  });

  await subscriber.start();
  // await subscriber.stop();
}
github Zilliqa / Zilliqa-JavaScript-Library / examples / newTxBlockSubscriptions.js View on Github external
const subscriber = zilliqa.subscriptionBuilder.buildNewBlockSubscriptions(
    'ws://',
  );
  subscriber.emitter.on(StatusType.SUBSCRIBE_NEW_BLOCK, (event) => {
    console.log('get SubscribeNewBlock echo: ', event);
  });

  subscriber.emitter.on(MessageType.NEW_BLOCK, (event) => {
    console.log('get new block: ', event.value.TxBlock.header);
  });

  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
    console.log('get unsubscribe event: ', event);
  });

  subscriber.emitter.on(SocketConnect.CLOSE, (event) => {
    console.log('get socket close: ', event);
  });

  subscriber.emitter.on(SocketConnect.ERROR, (event) => {
    console.log('get socket error: ', event);
  });

  await subscriber.start();
  // await subscriber.stop();
}
github Zilliqa / Zilliqa-JavaScript-Library / examples / newTxBlockSubscriptions.js View on Github external
console.log('get SubscribeNewBlock echo: ', event);
  });

  subscriber.emitter.on(MessageType.NEW_BLOCK, (event) => {
    console.log('get new block: ', event.value.TxBlock.header);
  });

  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
    console.log('get unsubscribe event: ', event);
  });

  subscriber.emitter.on(SocketConnect.CLOSE, (event) => {
    console.log('get socket close: ', event);
  });

  subscriber.emitter.on(SocketConnect.ERROR, (event) => {
    console.log('get socket error: ', event);
  });

  await subscriber.start();
  // await subscriber.stop();
}
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa / src / index.ts View on Github external
constructor(node: string, websocket: string, provider?: Provider) {
    this.provider = provider || new HTTPProvider(node);
    this.wallet = new Wallet(this.provider);
    this.blockchain = new Blockchain(this.provider, this.wallet);
    this.network = new Network(this.provider, this.wallet);
    this.contracts = new Contracts(this.provider, this.wallet);
    this.transactions = new TransactionFactory(this.provider, this.wallet);
    this.newTxBlockSubscription = new NewTxBlockSubscription(websocket);
  }
}