hardhat/types#RequestArguments TypeScript Examples

The following examples show how to use hardhat/types#RequestArguments. 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: provider.ts    From hardhat-kms-signer with MIT License 5 votes vote down vote up
public async request(args: RequestArguments): Promise<unknown> {
    const method = args.method;
    const params = this._getParams(args);

    if (method === "eth_sendTransaction") {
      const tx: JsonRpcTransactionData = params[0];

      if (tx !== undefined && tx.from === undefined) {
        tx.from = await this._getSender();
      }
      const [txRequest] = validateParams(params, rpcTransactionRequest);

      if (txRequest.nonce === undefined) {
        txRequest.nonce = await this._getNonce(txRequest.from);
      }
      const txOptions = new Common({
        chain: await this._getChainId(),
        hardfork: Hardfork.London,
      });

      const txParams: FeeMarketEIP1559TxData = pick(txRequest, [
        "from",
        "to",
        "value",
        "nonce",
        "data",
        "chainId",
        "maxFeePerGas",
        "maxPriorityFeePerGas",
      ]);
      txParams.gasLimit = txRequest.gas;
      const txf = FeeMarketEIP1559Transaction.fromTxData(txParams, {
        common: txOptions,
      });

      const txSignature = await createSignature({
        keyId: this.kmsKeyId,
        message: txf.getMessageToSign(),
        address: tx.from!,
        txOpts: txOptions,
      });

      const signedTx = FeeMarketEIP1559Transaction.fromTxData(
        {
          ...txParams,
          ...txSignature,
        },
        {
          common: txOptions,
        }
      );

      const rawTx = `0x${signedTx.serialize().toString("hex")}`;
      return this._wrappedProvider.request({
        method: "eth_sendRawTransaction",
        params: [rawTx],
      });
    } else if (
      args.method === "eth_accounts" ||
      args.method === "eth_requestAccounts"
    ) {
      return [await this._getSender()];
    }

    return this._wrappedProvider.request(args);
  }