@injectivelabs/web3-strategy
TypeScript icon, indicating that this package has built-in type declarations

0.5.45 • Public • Published

🌟 Injective Protocol - Web3 Strategy

downloads npm-version license

A convenient way to use Web3 with a transaction signing provider.


📚 Installation

yarn add @injectivelabs/web3-strategy

📖 Documentation

// file: web3.ts
import { ChainId } from "@injectivelabs/ts-types"
import { Web3Strategy, Wallet, ConcreteStrategyOptions } from "@injectivelabs/web3-strategy";

/*
** Injective Chain's ChainId, Mainnet ChainId
** and other values can be used, but RPC and WS
** endpoint MUSt be provided for the ChainId
*/
const chainId: ChainId = 888
const pollingInterval = 500 // RPC's polling interval
const wallet = Wallet.Metamask
const privateKey = process.env.PRIVATE_KEY // Used only for Wallet based Subprovider (not needed for Metamask)

const getRpcUrlsForChainIds = () => {
  return {
    888: "http://localhost:1317",
  };
};

const getWsRpcUrlsForChainIds = () => {
  return {
    888: "ws://localhost:1317",
  };
};

const options = {
    pollingInterval,
    privateKey,
    wsRpcUrls: getWsRpcUrlsForChainIds(),
    rpcUrls: getRpcUrlsForChainIds(),
}: ConcreteStrategyOptions

export const web3Strategy = new Web3Strategy({
  chainId,
  options
  wallet,
})
// file: sign.service.ts
import { web3Strategy } from 'app/web3';

const transaction = /* ... */;
const txHash = await web3Strategy.sendTransaction(transaction, address);

📜 Contribution

Contribution guides and practices will be available once there is a stable foundation of the whole package set within the injective-ts repo.


Support

Reach out to us at one of the following places!


🔓 License

License

Readme

Keywords

none

Package Sidebar

Install

npm i @injectivelabs/web3-strategy

Weekly Downloads

1

Version

0.5.45

License

MIT

Unpacked Size

137 kB

Total Files

103

Last publish

Collaborators

  • mmeloni
  • hmoragrega
  • shane-moore
  • phucta
  • thomasralee
  • albertchon
  • bangjelkoski
  • markuswaas
  • maximshen