npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@btq-js/web3-provider

v0.0.38

Published

This library follows the [EIP-1193][eip-1193] proposal, providing access to `BTQ network`.

Downloads

20

Readme

@btq-js/web3-provider

This library follows the EIP-1193 proposal, providing access to BTQ network.

What is BTQ Network

Traditional blockchains like Bitcoin and Ethereum are vulnerable to quantum attacks. The BTQ Network is a quantum-resistant blockchain designed to protect your assets against the threats of quantum computing.

Signature Scheme and Quantum Security

In order to become quantum-resistant, we at BTQ use Falcon, a post-quantum digital signature, to replace the current ECDSA signature in Ethereum. Falcon is selected by NIST as a post-quantum cryptography standard for digital signatures, which ensures compactness and efficiency with provable security.

BTQ technologies are used to maintain the same level of efficiency as Ethereum, even with the use of post-quantum cryptography.

📝 We use different signature scheme then standard Ethereum, the HDWalletProvider reflects these change.

🧪 Try out Sign transaction to see our falcon signature.

Please note that:

This package depends on @btq-js/falcon-js by default. If we want to change the underlying falcon implementation from javascript to web assembly, please follw these simple steps

Getting started

JSON-RPC Provider

Provides access to JSON-RPC server. Currently support HTTP and Websocket.

import { JsonRpcProvider } from '@btq-js/web3-provider';

const jsonRpcProvider = new JsonRpcProvider({
  url: 'https://your-rpc.com:port' /* or ws:// */,
});

jsonRpcProvider
  .request({ method: 'eth_chainId' })
  .then((chainId) => {
    console.log('chainId (dec): ', Number.parseInt(chainId, 16)); // 222
    console.log('chainId (hex): ', chainId); // 0xde
  })
  .then(() => process.exit(0));

HD Wallet Provider

Provides basic HD wallet functionality on top of JSON-RPC server.

import { HDWalletProvider } from '@btq-js/web3-provider';

const nodeUrl = 'https://your-rpc.com';
const mnemonic = 'nasty rose intact edge chicken vanish ghost orient laugh ...';

async function signTransaction() {
  const hdWalletProvider = await HDWalletProvider.fromMnemonic(mnemonic, {
    url: nodeUrl,
    chainId: 222 /* btq */,
  });

  const signature = await hdWalletProvider.request({
    method: 'eth_signTransaction',
    params: {
      from: '0x0000000000000000000000000000000000000001',
      to: '0x0000000000000000000000000000000000000002',
      value: 123,
      nonce: 6,
      gasPrice: 24,
      gas: 39752,
    },
  });

  console.log(signature);
}

signTransaction().then(() => process.exit(0));

Web3 initialization

Wrap the provider with Web3.js for ease-of-use.

import { JsonRpcProvider } from '@btq-js/web3-provider';
import Web3 from 'web3';

const web3 = new Web3(new JsonRpcProvider({ url: 'ws://3.113.200.235:8546' }));

web3.eth
  .getGasPrice()
  .then((gasPrice) => {
    console.log(`Gas price: ${gasPrice} wei`);
  })
  .then(() => process.exit());

📝 Note: You can check which RPC method is called to fulfill each function call by looking their definitions.

Examples

Example 1: Log chainId

// with JsonRpcProvider
jsonRpcProvider.request({ method: 'eth_chainId' }).then((chainId) => {
  console.log('chainId (dec): ', Number.parseInt(chainId, 16)); // chainId (hex):  222
  console.log('chainId (hex): ', chainId); // chainId (hex):  0xde
});

// or with web3.js
web3.eth.getChainId().then((chainId) => {
  console.log('chainId (dec): ', chainId); // chainId (hex):  222
  console.log('chainId (hex): ', web3.utils.toHex(chainId)); // chainId (hex):  0xde
});

Example 2: Log latest block

// with JsonRpcProvider
provider.request({ method: 'eth_getBlockByNumber', params: ['latest', false] }).then((block) => {
  console.log(block);
});

// or with web3.js
web3.eth.getBlock('latest').then((block) => {
  console.log(block);
});

Example 3: Sign transaction

// with HDWalletProvider
const signed = await hdWalletProvider.request({
  method: 'eth_signTransaction',
  params: {
    from: '0x5407286398cc7dd22215cff9625075e58745b043',
    to: '0xfa30e62eedcf80d47d42947fbcc034beed5c09fe',
    value: 0,
    nonce: 6,
    gasPrice: 24,
    gas: 39752,
  },
});

// or with web3.js
const signed = await web3.eth.signTransaction({
  from: '0x5407286398cc7dd22215cff9625075e58745b043',
  to: '0xfa30e62eedcf80d47d42947fbcc034beed5c09fe',
  value: 0,
  nonce: 6,
  gasPrice: 24,
  gas: 39752,
});

Example 4: Log available accounts

// with HDWalletProvider
const accounts = await provider.request({ method: 'eth_accounts' });

// or with web3.js
const accounts = await web3.eth.getAccounts();

Example 5: Listen for new block headers

📝 Note: This requires WebSocket connection (ws:// or wss://)

// subscribe to new block headers
const subscriptionId = await provider.request({
  method: 'eth_subscribe',
  params: ['newHeads'],
});

// add event listener for new block headers
provider.on('message', (message) => {
  console.log(message.data.result);
});

// Unsubscribe from new block headers
provider.request({ method: 'eth_unsubscribe', params: [subscriptionId] }).then((success) => {
  if (success) console.log('unsubscribe newHeads');
});

Or with web3.js

// Subscribe to new block headers
const subscription = await web3.eth.subscribe('newBlockHeaders', (error, blockHeader) => {
  if (error) return;
  console.log(blockHeader);
});

// Unsubscribe from new block headers
subscription.unsubscribe((error, success) => {
  if (success) console.log('unsubscribe newHeads');
});