How to use the web3-eth-accounts.default function in web3-eth-accounts

To help you get started, we’ve selected a few web3-eth-accounts 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 melonproject / protocol / src / utils / environment / initTestEnvironment.ts View on Github external
// Pass in Ganache.provider but only if
    // process.env.JSON_RPC_ENDPOINT is not set
    endpoint: process.env.JSON_RPC_ENDPOINT,
    logger: testLogger,
    provider: !process.env.JSON_RPC_ENDPOINT && getGanache(),
  });
  const accounts = await environment.eth.getAccounts();

  ensure(
    keyPairs.has(accounts[0].toLowerCase()),
    `Unknown address: ${
      accounts[0]
    }. Are you running ganache with the right mnemonic: ${testMnemonic}`,
  );

  const web3Accounts = new Web3Accounts(environment.eth.currentProvider);

  const signer = (unsignedTransaction, from = new Address(accounts[0])) =>
    web3Accounts
      .signTransaction(unsignedTransaction, keyPairs.get(from.toLowerCase()))
      .then(t => t.rawTransaction);

  const enhancedEnvironment = {
    ...environment,
    wallet: {
      address: accounts[0],
      sign: signer,
    },
  };

  return enhancedEnvironment;
};
github melonproject / protocol / src / utils / environment / withNewAccount.ts View on Github external
const withNewAccount = async (environment: Environment) => {
  const log = getLog(environment);

  const web3Accounts = new Web3Accounts(environment.eth.currentProvider);

  const account = web3Accounts.create();

  const enhancedEnvironment = await withPrivateKeySigner(
    environment,
    account.privateKey,
  );

  if (process.env.NODE_ENV !== 'production') {
    log.info('New account created with privateKey:', account.privateKey);
  }

  return enhancedEnvironment;
};
github melonproject / protocol / src / utils / environment / withPrivateKeySigner.ts View on Github external
const withPrivateKeySigner = async (
  environment: Environment,
  privateKey: string,
) => {
  const web3Accounts = new Web3Accounts(environment.eth.currentProvider);

  const { address } = web3Accounts.privateKeyToAccount(privateKey);

  const signer = unsignedTransaction =>
    web3Accounts
      .signTransaction(unsignedTransaction, privateKey)
      .then(t => t.rawTransaction);

  const withWallet = {
    ...environment,
    wallet: {
      address,
      sign: signer,
    },
  };
github melonproject / protocol / src / utils / environment / withKeystoreSigner.ts View on Github external
const withKeystoreSigner = (
  environment: Environment,
  { keystore, password }: WithKeystoreSignerArgs,
) => {
  const web3Accounts = new Web3Accounts(environment.eth.currentProvider);

  const account = web3Accounts.decrypt(keystore, password);
  const sign = async unsignedTransaction => {
    const signedTransaction = await account.signTransaction(
      unsignedTransaction,
    );
    return signedTransaction.rawTransaction;
  };

  const enhancedEnvironment = {
    ...environment,
    wallet: {
      address: account.address,
      sign,
    },
  };

web3-eth-accounts

Package for managing Ethereum accounts and signing

LGPL-3.0
Latest version published 27 days ago

Package Health Score

98 / 100
Full package analysis

Similar packages