delayedWithdraw function

Future<String?> delayedWithdraw(
  1. Token token,
  2. String privateKey, {
  3. BigInt? gasLimit,
  4. int gasPrice = 0,
})

Makes the final withdrawal from the WithdrawalDelayer smart contract after enough time has passed.

@param {Object} token - The token information object as returned from the API @param {String} providerUrl - Network url (i.e, http://localhost:8545). Optional @param {Object} signerData - Signer data used to build a Signer to send the transaction @param {Number} gasLimit - Optional gas limit @param {Number} gasPrice - Optional gas price

Implementation

Future<String?> delayedWithdraw(Token token, String privateKey,
    {BigInt? gasLimit, int gasPrice = 0}) async {
  final credentials =
      await HermezSDK.currentWeb3Client!.credentialsFromPrivateKey(privateKey);
  final from = await credentials.extractAddress();

  if (gasLimit == null) {
    gasLimit = await delayedWithdrawGasLimit(from.hex, token);
  }

  EtherAmount ethGasPrice;
  if (gasPrice > 0) {
    ethGasPrice = EtherAmount.inWei(BigInt.from(gasPrice));
  } else {
    ethGasPrice = await HermezSDK.currentWeb3Client!.getGasPrice();
  }

  int nonce = await HermezSDK.currentWeb3Client!
      .getTransactionCount(from, atBlock: BlockNum.pending());

  final withdrawalDelayerContract = await ContractParser.fromAssets(
      'WithdrawalDelayerABI.json',
      getCurrentEnvironment()!.contracts[ContractName.withdrawalDelayer]!,
      ContractName.withdrawalDelayer);

  final transactionParameters = [
    from,
    token.id == 0 ? 0x0 : EthereumAddress.fromHex(token.ethereumAddress!)
  ];

  Transaction transaction = Transaction.callContract(
      contract: withdrawalDelayerContract,
      function: _withdrawal(withdrawalDelayerContract),
      parameters: transactionParameters,
      maxGas: gasLimit.toInt(),
      gasPrice: ethGasPrice,
      nonce: nonce);

  String? txHash;
  try {
    txHash = await HermezSDK.currentWeb3Client!.sendTransaction(
        credentials, transaction,
        chainId: getCurrentEnvironment()!.chainId);
  } catch (e) {
    print(e.toString());
  }

  print(txHash);

  return txHash;
}