0.0.38 • Published 1 year ago

@johnny2022/web3-provider v0.0.38

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@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..."}
})