ethers#UnsignedTransaction TypeScript Examples

The following examples show how to use ethers#UnsignedTransaction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: faucet.ts    From hoprnet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Takes an array of transactions, signs them and
 * broadcasts them.
 * @param signer Used to sign transactions
 * @param txparams the transaction
 */
async function send(signer: providers.JsonRpcSigner, txparams: UnsignedTransaction): Promise<void> {
  try {
    const tx = await signer.sendTransaction(txparams)
    const txReceipt = await tx.wait()
    console.log(`Funding transaction included on-chain in block #${txReceipt.blockNumber}`)
  } catch (err) {
    console.log(`Error: ${err}`)
  }
}
Example #2
Source File: faucet.ts    From hoprnet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates two transaction: one that sends ETH to the address
 * and a second one which sends HOPR tokens to that address
 * @param token instance of the HOPR token
 * @param address where to send the HOPR tokens and ETH to
 * @param amountEth how many ETH
 * @param amountHopr how many HOPR
 * @param networkName which network to use
 * @returns
 */
async function createTransaction(
  token: HoprToken,
  address: string,
  amountEth: BigNumber,
  amountHopr: BigNumber,
  networkName: string
): Promise<UnsignedTransaction[]> {
  const txs: UnsignedTransaction[] = [
    await token.populateTransaction.mint(address.toString(), amountHopr, constants.HashZero, constants.HashZero, {
      gasLimit: 200e3
    }),
    {
      to: address,
      value: amountEth
    }
  ]

  console.log(`?? Sending ${utils.formatEther(amountEth)} ETH to ${address} on network ${networkName}`)
  console.log(`?? Sending ${utils.formatEther(amountHopr)} HOPR to ${address} on network ${networkName}`)

  return txs
}
Example #3
Source File: index.ts    From ethers-aws-kms-signer with MIT License 5 votes vote down vote up
async signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string> {
    const unsignedTx = await ethers.utils.resolveProperties(transaction);
    const serializedTx = ethers.utils.serializeTransaction(<UnsignedTransaction>unsignedTx);
    const transactionSignature = await this._signDigest(ethers.utils.keccak256(serializedTx));
    return ethers.utils.serializeTransaction(<UnsignedTransaction>unsignedTx, transactionSignature);
  }