@injectivelabs/web3-strategy
v0.5.45
Published
A convenient way to use Web3 with a transaction signing provider.
Downloads
307
Maintainers
Keywords
Readme
🌟 Injective Protocol - Web3 Strategy
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!
- Website at
injectiveprotocol.com
- Twitter at
@InjectiveLabs