forceExit function
Future<String?>
forceExit(
- HermezCompressedAmount amount,
- String? accountIndex,
- Token token,
- String privateKey, {
- dynamic gasLimit = GAS_LIMIT,
- dynamic gasPrice = GAS_MULTIPLIER,
Makes a force Exit. This is the L1 transaction equivalent of Exit.
@param {BigInt} amount - The amount to be withdrawn @param {String} accountIndex - The account index in hez address format e.g. hez:DAI:4444 @param {Object} token - The token information object as returned from the API @param {Object} privateKey - Signer data used to build a Signer to send the transaction @param {Number} gasLimit - Optional gas limit @param {Number} gasMultiplier - Optional gas multiplier
Implementation
Future<String?> forceExit(HermezCompressedAmount amount, String? accountIndex,
Token token, String privateKey,
{gasLimit = GAS_LIMIT, gasPrice = GAS_MULTIPLIER}) async {
final hermezContract = await ContractParser.fromAssets('HermezABI.json',
getCurrentEnvironment()!.contracts['Hermez']!, "Hermez");
final credentials =
await HermezSDK.currentWeb3Client!.credentialsFromPrivateKey(privateKey);
final from = await credentials.extractAddress();
EtherAmount ethGasPrice = EtherAmount.inWei(BigInt.from(gasPrice));
int nonce = await HermezSDK.currentWeb3Client!
.getTransactionCount(from, atBlock: BlockNum.pending());
final transactionParameters = [
BigInt.zero,
BigInt.from(getAccountIndex(accountIndex)),
BigInt.zero,
BigInt.from(amount.value),
BigInt.from(token.id!),
BigInt.one,
hexToBytes('0x')
];
print(transactionParameters);
Transaction transaction = Transaction.callContract(
contract: hermezContract,
function: _addL1Transaction(hermezContract),
parameters: transactionParameters,
maxGas: gasLimit,
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;
}