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

0.0.38 • Public • Published

@johnny2022/web3-provider

A commonplace web3 provider. Use it to sign and send transactions, to retrieve data, and generate accounts.

Install

$ npm install @johnny2022/web3-provider --save

Examples

Initialize with mnemonic

const Web3 = require("web3");
const Web3Provider = require("@johnny2022/web3-provider");

const chainId = 1
const mnemonicPhrase = "mountains supernatural bird..."; // 12 word mnemonic
let provider = new Web3Provider({
  mnemonic: {
    phrase: mnemonicPhrase
  },
  providerOrUrl: "http://localhost:8545",
  chainSettings: { chainId }
});

Initialize with private key

const Web3 = require("web3");
const Web3Provider = require("@johnny2022/web3-provider");

const chainId = 1
const privateKey = "0x000111......"; 
let provider = new Web3Provider({
  privateKeys: [
    privateKey
  ],
  providerOrUrl: "http://localhost:8545",
  chainSettings: { chainId }
});

Initialize with public key

const Web3 = require("web3");
import { InitializeEthereumWithPublicKey } from "@johnny2022/web3-provider"

const chainId = 1
const publicKey = "0x000111......"; 
InitializeEthereumWithPublicKey("http://localhost:8545", chainId, publicKey);

Create your account and output mnemonic, private key and public key

import { Web3Wallet } from "@johnny2022/web3-provider"

const chainId = 1
let password = "123456"
new Web3Wallet().createAccount(chainId, password)
.then(acc => {
  console.log(acc)
  // It will be output the {mnemonic: "hello world ...", publicKey: "0x0...", privateKey: "0x1..."}
})

Package Sidebar

Install

npm i @johnny2022/web3-provider

Repository

github.com/

Weekly Downloads

0

Version

0.0.38

License

MIT

Unpacked Size

393 kB

Total Files

108

Last publish

Collaborators

  • johnny2022