How to use the ethers.ethers.utils 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 ethereum-optimism / optimism / packages / message-relayer / src / relay-tx.ts View on Github external
const messages = await getMessagesByTransactionHash(
    l2RpcProvider,
    l2CrossDomainMessengerAddress,
    l2TransactionHash
  )

  const messagePairs: CrossDomainMessagePair[] = []
  for (const message of messages) {
    // We need to calculate the specific storage slot that demonstrates that this message was
    // actually included in the L2 chain. The following calculation is based on the fact that
    // messages are stored in the following mapping on L2:
    // https://github.com/ethereum-optimism/optimism/blob/c84d3450225306abbb39b4e7d6d82424341df2be/packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_L2ToL1MessagePasser.sol#L23
    // You can read more about how Solidity storage slots are computed for mappings here:
    // https://docs.soliditylang.org/en/v0.8.4/internals/layout_in_storage.html#mappings-and-dynamic-arrays
    const messageSlot = ethers.utils.keccak256(
      ethers.utils.keccak256(
        encodeCrossDomainMessage(message) +
          remove0x(l2CrossDomainMessengerAddress)
      ) + '00'.repeat(32)
    )

    // We need a Merkle trie proof for the given storage slot. This allows us to prove to L1 that
    // the message was actually sent on L2.
    const stateTrieProof = await getStateTrieProof(
      l2RpcProvider,
      l2Transaction.blockNumber,
      predeploys.OVM_L2ToL1MessagePasser,
      messageSlot
    )

    // State roots are published in batches to L1 and correspond 1:1 to transactions. We compute a
    // Merkle root for these state roots so that we only need to store the minimum amount of
github ethereum-optimism / optimism / packages / data-transport-layer / src / services / l1-ingestion / handlers / sequencer-batch-appended.ts View on Github external
const maybeDecodeSequencerBatchTransaction = (
  transaction: Buffer
): DecodedSequencerBatchTransaction | null => {
  try {
    const decodedTx = ethers.utils.parseTransaction(transaction)

    return {
      nonce: BigNumber.from(decodedTx.nonce).toNumber(),
      gasPrice: BigNumber.from(decodedTx.gasPrice).toNumber(),
      gasLimit: BigNumber.from(decodedTx.gasLimit).toString(),
      value: toRpcHexString(decodedTx.value),
      target: toHexString(decodedTx.to), // Maybe null this out for creations?
      data: toHexString(decodedTx.data),
      sig: {
        v: BigNumber.from(decodedTx.v).toNumber(),
        r: toHexString(decodedTx.r),
        s: toHexString(decodedTx.s),
      },
    }
  } catch (err) {
    return null
github unlock-protocol / unlock / unlock-js / src / __tests__ / helpers / walletServiceHelper.ethers.js View on Github external
export const prepContract = ({
  contract,
  functionName,
  signature = '',
  nock,
  value,
}) => {
  const unlockInterface = new ethers.utils.Interface(contract.abi)

  return (...args) => {
    const encodedValue = value ? utils.toWei(value, 'ether') : 0
    const testParams = {
      gas: utils.hexStripZeros(utils.hexlify(GAS_AMOUNTS[functionName])),
      to: checksumContractAddress,
      data: unlockInterface.functions[`${functionName}(${signature})`].encode(
        args
      ),
      from: testAccount,
      ...(value ? { value: utils.hexlify(encodedValue) } : {}),
    }

    const testTransaction = {
      blockHash: null,
      blockNumber: null,
github airswap / AirSwap.js / src / utils / transformations.js View on Github external
if (!(transaction && transaction.to)) {
    return {}
  }
  const to = transaction.to.toLowerCase()
  const abi = abis[to.toLowerCase()]
  if (!abi) {
    return {}
  }
  const contractInterface = new ethers.utils.Interface(abi)
  const { data } = transaction
  const parsed = contractInterface.parseTransaction({ data })
  const name = parsed.name
  const parameterKeys = _.map(contractInterface.functions[name].inputs, 'name')
  const parameterValues = _.map(parsed.args, s => (s.toString ? s.toString() : s).toLowerCase())
  const parameters = _.zipObject(parameterKeys, parameterValues)
  const value = ethers.utils.formatEther(transaction.value)

  return {
    name,
    parameters:
      to === SWAP_CONTRACT_ADDRESS || to === WRAPPER_CONTRACT_ADDRESS ? parseSwapParameters(parameters) : parameters,
    formattedETHValue: value,
  }
}
github airswap / AirSwap.js / src / wallet / redux / middleware.js View on Github external
const tokens = tokenSelectors.getTokens(state)
      const order = tokenSelectors.makeGetReadableOrder(state)(parameters)

      const { tokenAddress } = order
      gasLimit = _.get(_.find(tokens, { address: tokenAddress }), 'gasLimit', 400000)
    } else if (parsed.name === 'setRuleAndIntent') {
      gasLimit = 500000
    } else if (parsed.name === 'createDelegate') {
      gasLimit = 3000000
    } else if (parsed.name === 'createIndex') {
      gasLimit = 1500000
    }

    const { gwei } = gasSelectors.getCurrentGasPriceSettings(state)

    const gasPrice = ethers.utils.parseUnits(`${gwei}`, 'gwei').toNumber()
    return {
      gasLimit: Number(gasLimit),
      gasPrice,
    }
  } else if (actionType === 'signMessage') {
    params = { signatureText: args }
    store.dispatch({
      type: 'START_WALLET_ACTION',
      actionType,
      params,
    })
  } else if (actionType === 'signTypedData') {
    params = { signatureText: args }
    store.dispatch({
      type: 'START_WALLET_ACTION',
      actionType,
github daostack / DAOstack-Hackers-Kit / starter-template / starter-app / src / App.js View on Github external
constructor(props) {
    super(props)
    this.state = {
      arcIsInitialized: false,
      arc: null,
      dao: null,
      daos: null,
      proposals: [],
      proposalCreateOptionsCR: {
        description: "Please provide Sample proposal description",
        title: "Sample Proposal",
        url: "#",
        scheme: "",
        beneficiary: (window).ethereum.selectedAddress,
        nativeTokenReward: "",
        reputationReward: eth.utils.parseEther('100').toString(),
        ethReward: eth.utils.parseEther('1').toString(),
        externalTokenReward: "",
        externalTokenAddress: "",
        periodLength: "",
        periods: ""
      },
      stakeAmount: '100',
    }
    this.handleChange = this.handleChange.bind(this);
    this.handleCreateProposal = this.handleCreateProposal.bind(this);
    this.handleStake = this.handleStake.bind(this);
  }
github tasitlabs / tasit-sdk / packages / contract-based-account / src / GnosisSafeUtils.ts View on Github external
(wallet: {
        privateKey: string | ArrayLike | ethers.utils.HDNode.HDNode;
      }) => {
        const signingKey = new ethers.utils.SigningKey(wallet.privateKey);
        const sig = signingKey.signDigest(hash);
        signatures += ethers.utils.joinSignature(sig).slice(2);
      }
    );
github rainbow-me / rainbow / src / handlers / uniswap.js View on Github external
const convertValueForEthers = value => {
  const valueBigNumber = ethers.utils.bigNumberify(value.toString());
  return ethers.utils.hexlify(valueBigNumber);
};