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

@con3x/web3-plugin-near

v1.0.7

Published

web3.js plugin for Near Protocol

Downloads

5

Readme

web3.js plugin for NEAR Protocol

Dependency Status

This is an npm package containing a web3.js plugin for NEAR Protocol.

Plugin usage by users

At your typescript project first run: yarn add web3 @con3x/web3-plugin-near

And here is how to use the plugin:

import { Web3 } from 'web3';
import { NearPlugin } from '@con3x/web3-plugin-near';

async function near() {
  const web3 = new Web3('https://archival-rpc.mainnet.near.org');
  web3.registerPlugin(new NearPlugin());

  const blockNumber = await web3.near.getBlockNumber({ finality: 'final' });
  console.log('near blockNumber', blockNumber);

  const block = await web3.near.getBlock({
    blockId: 'EgG4dp1j1doy8kMaTx7j715nn9K7QXGByi8QUyRdSned',
  });
  console.log('near block', block);

  // Hint: you can try to give a blockId that does not exist in order to see the error returned by web3.js
  // try {
  //   const invalidBlock = await web3.near.getBlock({
  //     blockId: 'xyz',
  //   });
  // } catch (error) {
  //   console.log(error);
  // }
}

near();

You can play with the npm package online at: https://codesandbox.io/p/sandbox/broken-haze-9krygq?file=%2Findex.js

Project progress

NEAR Plugin

Create NEAR Plugin and publish it to the npm registry

The web3.js plugin for NEAR has been publish to
https://www.npmjs.com/package/@con3x/web3-plugin-near and it is useable inside this example playground: https://codesandbox.io/p/sandbox/broken-haze-9krygq?file=%2Findex.js Additionally, some tests has been written to test some of the functionality.

Implement all basic NEAR RPC methods

However, there is a difference between calling those function at near-api-js and in this plugin. In this plugin, the internal handling is similar to web3.js. So the provider errors could be caught in the same way the developer would catch with web3.js.

Implement alternative methods to ethereum RPC methods available currently at web3.eth.[RPC_METHOD]

Implement web3.near.accounts that act a bit similar to web3.eth.accounts

Implement web3.near.Contract that act a bit similar to web3.eth.Contract

NEAR Aurora Plugin

There is a web3.js plugin for the Aurora Engine that is an EVM running atop NEAR Protocol. You can check its repository at: https://github.com/con3x/web3-plugin-aurora

Running Tests

Testing NearPlugin

Executing yarn test would give something like:

 PASS  test/near-plugin.test.ts
  NearPlugin Tests
    NearPlugin method tests
      ✓ should call `getBlockNumber` method with expected param (10 ms)
      ✓ should call `block` method with expected param (3 ms)
      ✓ should call `getProtocolVersion` (3 ms)
      ✓ should call `isSyncing` (2 ms)
      ✓ should call `getGasPrice` (2 ms)
      ✓ should call `getCoinbase` (2 ms)
      ✓ should call `getBalance` (2 ms)
      ...

Test Suites: 1 passed, 1 total
Tests:       xx passed, xx total
Snapshots:   0 total
Time:        1.685 s, estimated 2 s
Ran all test suites.
Done in 2.16s.

Note: Before running the tests, be sure to run a NEAR development node on port . You can follow the documentation to run a local testnet: https://near-nodes.io/validator/running-a-node.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.