[ingan project] Create ingan account

in hive-151113 •  9 months ago 

I have implemented a function to create an steem account with Flutter code.

This is the code:

Future<dynamic> createAccountByACT({
    required String account,
    required String password,
  }) async {
    // get the creator account and its private key
    final creator = dotenv.env['CREATOR_ACCOUNT']!;
    final creatorPrivateWif = dotenv.env['CREATOR_ACTIVEKEY']!;

    //// create private keys
    final ownerKey = PrivateKey.fromLogin(account, password, 'owner');
    final activeKey = PrivateKey.fromLogin(account, password, 'active');
    final postingKey = PrivateKey.fromLogin(account, password, 'posting');
    final memoKey = PrivateKey.fromLogin(
      account,
      password,
      'memo',
    ).createPublic(client.addressPrefix);

    final ownerAuth = AccountKeyAuth(
      weight_threshold: 1,
      account_auths: [],
      key_auths: [
        [ownerKey.createPublic(client.addressPrefix), 1]
      ],
    );

    final activeAuth = AccountKeyAuth(
      weight_threshold: 1,
      account_auths: [],
      key_auths: [
        [activeKey.createPublic(client.addressPrefix), 1]
      ],
    );

    final postingAuth = AccountKeyAuth(
      weight_threshold: 1,
      account_auths: [],
      key_auths: [
        [postingKey.createPublic(client.addressPrefix), 1]
      ],
    );

    final operation = AccountCreationOperation(
      creator: creator,
      new_account_name: account,
      owner: ownerAuth,
      active: activeAuth,
      posting: postingAuth,
      memo_key: memoKey,
      json_metadata: '{"tags": ["ingan"]}',
      extensions: [],
    );

    //// send creation operation
    //create operation to transmit
    final createOperation = [
      [
        'create_claimed_account',
        operation,
      ]
    ];

    try {
      final result = await sendOperations(
        username: creator,
        operations: createOperation,
        wifKey: creatorPrivateWif,
      );
      printError('[DSteemApi | createAccountByACT] creation result. $result');
      return result;
    } catch (error) {
      printError(
          '[DSteemApi | createAccountByACT] failed to create the account. $error');
      return null;
    }
  }

I used to use dsteem library in the server side to create an account. But I ported this code to the Flutter (Dart code) code.

You can know how I could communicate dsteem library in the Dart code.

Now check if the account has been created successfully.

With the transactionId, the creation data can be retrieved. I will put additional data in the json_metadata.

More updates are coming soon.

#ingan

Posted through the ECblog app (https://blog.etain.club)

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!