deployAccount static method

Future<bool> deployAccount({
  1. required SecureStore secureStore,
  2. required Account account,
})

Implementation

static Future<bool> deployAccount({
  required SecureStore secureStore,
  required Account account,
}) async {
  final privateKey = await secureStore.getSecret(
      key: privateKeyKey(account.walletId, account.id));
  if (privateKey == null) {
    throw Exception("Private key not found");
  }

  s.StarkAccountSigner? signer = s.StarkAccountSigner(
      signer: s.StarkSigner(privateKey: s.Felt.fromHexString(privateKey)));

  final provider = WalletKit().provider;

  // call data depends on class hash...
  final constructorCalldata = [signer.publicKey];
  final tx = await s.Account.deployAccount(
    accountSigner: signer,
    provider: provider,
    constructorCalldata: constructorCalldata,
    classHash: WalletKit().accountClassHash,
  );
  signer = null;
  final (contractAddress, txHash) = tx.when(
    result: (result) =>
        (result.contractAddress, result.transactionHash.toHexString()),
    error: (error) => throw Exception('${error.code}: ${error.message}'),
  );
  bool success = await s.waitForAcceptance(
    transactionHash: txHash,
    provider: provider,
  );

  return success;
}