How to use the ethers.ethers.Wallet function in ethers

To help you get started, we’ve selected a few ethers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JoinColony / colonyNetwork / packages / reputation-miner / ReputationMiner.js View on Github external
this.ganacheProvider = new ethers.providers.Web3Provider(ganacheProvider);
      this.ganacheWallet = new ethers.Wallet(secretKey, this.ganacheProvider);
    }

    // This will have to support provider.getSigner https://docs.ethers.io/ethers.js/html/api-providers.html#jsonrpcprovider
    if (provider) {
      this.realProvider = provider;
    } else {
      this.realProvider = new ethers.providers.JsonRpcProvider(`http://localhost:${realProviderPort}`);
    }

    if (minerAddress) {
      this.minerAddress = minerAddress;
      this.realWallet = this.realProvider.getSigner(minerAddress);
    } else {
      this.realWallet = new ethers.Wallet(privateKey, this.realProvider);
      this.minerAddress = this.realWallet.address;
      // TODO: Check that this wallet can stake?
      this.minerAddress = this.realWallet.address;
      console.log("Transactions will be signed from ", this.realWallet.address);
    }
  }
github ethers-io / ethers.js / packages / cli / src.ts / cli.ts View on Github external
async function loadAccount(arg: string, plugin: Plugin, preventFile?: boolean): Promise {

    // Secure entry; use prompt with mask
    if (arg === "-") {
        let content = await getPassword("Private Key / Mnemonic:");
        return loadAccount(content, plugin, true);
    }

    // Raw private key
    if (ethers.utils.isHexString(arg, 32)) {
         let signer = new ethers.Wallet(arg, plugin.provider)
         return Promise.resolve(new WrappedSigner(signer.getAddress(), () => Promise.resolve(signer), plugin));
    }

    // Mnemonic
    if (ethers.utils.isValidMnemonic(arg)) {
        let signerPromise: Promise = null;
        if (plugin.mnemonicPassword) {
            signerPromise = getPassword("Password (mnemonic): ").then((password) => {
                let node = ethers.utils.HDNode.fromMnemonic(arg, password).derivePath(ethers.utils.defaultPath);
                return new ethers.Wallet(node.privateKey, plugin.provider);
            });
        } else {
            signerPromise = Promise.resolve(ethers.Wallet.fromMnemonic(arg).connect(plugin.provider));
        }

        return Promise.resolve(new WrappedSigner(
github ethers-io / ethers.js / packages / cli / lib.esm / cli.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
        // Secure entry; use prompt with mask
        if (arg === "-") {
            let content = yield getPassword("Private Key / Mnemonic:");
            return loadAccount(content, plugin, true);
        }
        // Raw private key
        if (ethers.utils.isHexString(arg, 32)) {
            let signer = new ethers.Wallet(arg, plugin.provider);
            return Promise.resolve(new WrappedSigner(signer.getAddress(), () => Promise.resolve(signer), plugin));
        }
        // Mnemonic
        if (ethers.utils.isValidMnemonic(arg)) {
            const mnemonic = arg;
            let signerPromise = null;
            if (plugin.mnemonicPassword) {
                signerPromise = getPassword("Password (mnemonic): ").then((password) => {
                    let node = ethers.utils.HDNode.fromMnemonic(mnemonic, password).derivePath(ethers.utils.defaultPath);
                    return new ethers.Wallet(node.privateKey, plugin.provider);
                });
            }
            else if (plugin._xxxMnemonicPasswordHard) {
                signerPromise = getPassword("Password (mnemonic; experimental - hard): ").then((password) => {
                    let passwordBytes = ethers.utils.toUtf8Bytes(password, ethers.utils.UnicodeNormalizationForm.NFKC);
                    let saltBytes = ethers.utils.arrayify(ethers.utils.HDNode.fromMnemonic(mnemonic).privateKey);
github smartcontractkit / chainlink / tools / ci-ts / test-helpers / common.ts View on Github external
export async function fundAddress(to: string, ether = 1000) {
  const gethMode = !!process.env.GETH_MODE || false
  const provider = createProvider()
  let signer: ethers.Signer
  if (gethMode) {
    signer = provider.getSigner(GETH_DEV_ADDRESS)
  } else {
    signer = new ethers.Wallet(DEVNET_PRIVATE_KEY).connect(provider)
  }
  const tx = await signer.sendTransaction({
    to,
    value: ethers.utils.parseEther(ether.toString()),
  })
  await tx.wait()
}
github ethers-io / ethers.js / packages / cli / src.ts / cli.ts View on Github external
signerPromise = getPassword("Password (mnemonic): ").then((password) => {
                let node = ethers.utils.HDNode.fromMnemonic(arg, password).derivePath(ethers.utils.defaultPath);
                return new ethers.Wallet(node.privateKey, plugin.provider);
            });
        } else {
github AdExNetwork / adex-platform / src / services / smart-contracts / actions / web3.js View on Github external
export const signTypedLocal = async ({ privateKey, authType, address, addrIdx, typedData, hash }) => {
	const wallet = new ethers.Wallet(privateKey)
	const hashBytes = ethers.utils.arrayify(hash)
	const sig = await wallet.signMessage(hashBytes)
	const signature = { sig: sig, hash, mode: SIGN_TYPES.EthPersonal.id }

	return signature
}
github loomnetwork / loom-js / src / dpos-user-v3.ts View on Github external
static async createOfflineUserAsync(params: GatewayUserParams): Promise {
    const provider = new ethers.providers.JsonRpcProvider(params.ethEndpoint)
    const wallet = new ethers.Wallet(params.ethereumPrivateKey!, provider)
    return DPOSUserV3.createUserAsync({
      wallet,
      ...params
    })
  }
github tasitlabs / tasit-sdk / packages / tasit-account / src / TasitAccount.js View on Github external
const createFromPrivateKey = privKey => {
  try {
    const wallet = new ethers.Wallet(privKey);
    return wallet;
  } catch (error) {
    throw new Error(`Error creating wallet: ${error.message}`);
  }
};