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

@two-point-five/web3-sdk

v0.3.3-preview

Published

This is an official 2p5 Web3 SDK for connecting to blockchain networks.

Downloads

3

Readme

Web3 SDK

This is an official 2p5 Web3 SDK for connecting to blockchain networks.

Table of Contents

Prerequisite

  1. NodeJS 18
  2. 2p5 Wallet

How to setup

  1. Run npm install

What's inside?

This turborepo uses npm as a package manager. It includes the following packages/apps:

Apps and Packages

Apps

  • docs: a Next.js app for creating web3-sdk documentation.
  • example-election: another Next.js app for experimenting web3-sdk package.
  • example-smartcontract: a Hardhat project for contract development in example-election project.

Packages

  • ~web3-sdk: Main Package.
  • eslint-config-custom: eslint configurations (includes eslint-config-next and eslint-config-prettier)
  • tsconfig: tsconfig.jsons used throughout the monorepo

Each package/app is 100% TypeScript.

Utilities

This turborepo has some additional tools already setup for you:

Build

To build all apps and packages, run the following command:

cd web3-sdk
npm run build

Develop

To develop all apps and packages, run the following command:

cd web3-sdk
npm run dev

if you want to test the package, you should start the project 2p5 Wallet first. and make sure the variable TPF_BASEURL_DEVELOPMENT in file packages/~web3-sdk/src/modules/widgets/WidgetManager.ts is same as the url in 2p5 Wallet project that you start before.

Remote Caching

Turborepo can use a technique known as Remote Caching to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.

By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can create one, then enter the following commands:

cd my-turborepo
npx turbo login

This will authenticate the Turborepo CLI with your Vercel account.

Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your turborepo:

npx turbo link

Useful Links

Learn more about the power of Turborepo:

How to use

With Web3.js

import Web3 from 'web3';
import TPFWeb, { withTPFProvider } from '@two-point-five/web3-sdk';

function initiateWeb3() {
  /**
   * string `test` is your dApp ID, but we haven't implemented it for now, so just fill it freely
   * string `goerli` is blockchain network. we have: "mainnet" | "goerli" | "sandbox2p5". choose one.
   * */
  const tpf = new TPFWeb('test', 'goerli', {
    environment: 'staging'
  });

  // pass the provider into Web3 instance
  const web3 = new Web3(tpf.provider);
  web3.eth.handleRevert = true;
  return web3;
}

/** example to get public address and balance */
async function getAccounts() {
  const web3 = initiateWeb3();
  try {
    const accounts = await web3.eth.getAccounts();
    const balance = await web3.eth.getBalance(accounts[0]);
    console.log({ accounts, balance });
  } catch (err) {
    console.error({ err });
  }
}
/**
 * of course, you can use `web3` instance like usual.
 * @see: https://web3js.readthedocs.io/en/v1.10.0/web3.html#example-local-geth-node
*/

// get TPF Provider
const provider = withTPFProvider(web3.currentProvider)
console.log(provider.isWalletConnected());
console.log(provider.getAccessToken());