Build on Flow | Learn FCL - 10. How to Create a New Testnet Account with Blocto Wallet
Tags: javascript, tutorial, onflow, blockchain
Published: 2022-06-28 19:57:06

## Overview

Our previous exploration of Flow Network were pretty harmless - scripts can’t change the state of the chain, they can just read the data from it. It’s time to change this and make some “dents” here and there. But in order to do this, we will need Flow account. It’s possible to do this in 4 different ways:

- Using **Blocto Wallet** (this is the topic of this post)
- Using [**Lilico Wallet**](https://dev.to/onflow/build-on-flow-learn-fcl-11-how-to-install-and-create-a-new-testnet-account-with-lillico-18i) - we are covering this in [Chapter 11](https://www.notion.so/Build-on-Flow-Learn-FCL-11-How-to-Install-and-Create-a-New-Testnet-Account-with-Lillico-33ed5bf0c36b4e25aa8d299a67342b2b)
- Via [**Flow Faucet**](https://testnet-faucet.onflow.org/) and **[Flow CLI](https://docs.onflow.org/flow-cli/)** - check [Chapter 12](https://www.notion.so/Build-on-Flow-Learn-FCL-12-How-to-Create-a-New-Account-with-Flow-CLI-7d1928a395b94549828632b167b578d2) of this series
- by signing and submitting a transaction, which would create new account (you need to have one, though 😛)

Personally, I gravitate toward the opinion that easiest way to make new account is Blocto Wallet. This is what we gonna do today:

- create new account with Blocto Wallet
- authenticate into account via FCL and Blocto Wallet
- get account balance, using wallet address

## How?

There are 2 ways to create new wallet with Blocto:

- using mobile app
- using FCL pop-up

There are multiple articles outlining the process of wallet creation with mobile app. For example:

- [https://dappradar.com/blog/how-to-install-and-use-blocto-wallet-on-flow](https://dappradar.com/blog/how-to-install-and-use-blocto-wallet-on-flow)
- [https://medium.com/bytenext/how-to-create-blocto-wallet-858ee3a9212c](https://medium.com/bytenext/how-to-create-blocto-wallet-858ee3a9212c)
- [https://avatarart.io/blog/details/how-to-create-blocto-wallet](https://avatarart.io/blog/details/how-to-create-blocto-wallet)

While mobile is great and all - we will reduce extra steps and create our wallet using FCL.

Blocto provides nice step-by-step instructions how to configure and then invoke login popup on their [doc site](https://docs.blocto.app/blocto-sdk/javascript-sdk/flow/login-register). We will use those bits and pieces to make `Blocto Wallet Creator` 🧙‍♂️!

### Step 1 - Installation

Add `"@onflow/fcl": "1.0.0"` as your dependency

### Step 2 - Setup

Just like the last time, we will import necessary methods and setup FCL:

```jsx
// Import methods from FCL
import { unauthenticate, logIn, config } from "@onflow/fcl";

// Specify the API endpoint - this time we will use Testnet
const api = "https://rest-testnet.onflow.org";

// This is the endpoint, which will be responsible for wallet authorization
const handshake = "https://flow-wallet-testnet.blocto.app/authn";

// Configure FCL to use mainnet as the access node
config()
  // connect to Flow testnet
  .put("accessNode.api", api)
  .put("challenge.handshake", handshake);
```

## Step 3 - Create Login Sequence

```jsx
// We will use IIFE to execute our code right away
(async () => {
  console.clear();

  // just in case we have authenticated user, we will log him out first
	await unauthenticate();

	// calling "logIn" will invoke "Sign in with Blocto - Testnet" popup
	const wallet = await logIn();

  console.log({ wallet });})();
})();
```

### Step 4 - Launch!

When the code will be executed, you should see popup with title “Sign in with Blocto `Testnet`"


![Blocto - Register](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gxufgeofgfamonl2ap1x.png)

Fill in your email address and press “Sign in / Register” button.

After that you should get a passcode in your inbox for the email you’ve provided on previous step.

![Blocto - PassCode](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jt70iji28korynqdzm3.png)

If the passcode is correct, Blocto popup will show your wallet address:


![Blocto - Confirm](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ccyg64zt15mvpqbxi1h.png)

After pressing “Confirm” button console log should be populated with account details (this is for my address, but yours should look similar):

```jsx
{
	f_type: "USER",
	f_vsn: "1.0.0",
	addr: "0xe7dd0f2ee4e077e2",
	cid: "ca88f086a545ce3c552d80",
	loggedIn: true,
	expiresAt: 1656443452552
}
```

Congratulations, now you are the owner of freshly baked Flow account 🍰!

### Step 5 - Get Account Balance

Let’s use our knowledge from previous post and fetch our  current balance. In order to do this, let’s update our imports:

```jsx
import { account, query, config } from "@onflow/fcl";
```

and update our IIEFE:

```jsx
// We will use IIFE to execute our code right away
(async () => {
  console.clear();
  await unauthenticate();

  const wallet = await logIn();
  console.log({ wallet });

	// We will take only "balance" field from account details
  const { balance }= await account(wallet.addr);
  const flowBalance = result.balance / Math.pow(10, 8);
  console.log({ flowBalance });
})();
```

That’s `0.001 FLOW` on your account. You are rich 🤑!

Until next time 👋

## Resources

- Codesandbox Wallet Creator - [https://codesandbox.io/s/dev-to-fcl-create-account-q60f2b](https://codesandbox.io/s/dev-to-fcl-create-account-q60f2b)
- Docs: Create Flow Wallet - [https://docs.onflow.org/flow-token/available-wallets/](https://docs.onflow.org/flow-token/available-wallets/)
- Blocto: Login / Register - [https://docs.blocto.app/blocto-sdk/javascript-sdk/flow/login-register#step-1-configure-fcl](https://docs.blocto.app/blocto-sdk/javascript-sdk/flow/login-register#step-1-configure-fcl)

Other resources you might find useful:

- **Flow Docs Site** - [https://docs.onflow.org/](https://docs.onflow.org/) - More detailed information about Flow blockchain and how to interact with it
- **Flow Portal** - [https://flow.com/](https://flow.com/) - your entry point to Flow
- **FCL JS** - [https://github.com/onflow/fcl-js](https://github.com/onflow/fcl-js) - Source code and ability to contribute to the FCL JS library
- **Cadence** - [https://docs.onflow.org/cadence/](https://docs.onflow.org/cadence/) - Introduction to Cadence
- **Codesandbox** - [https://codesandbox.io](https://codesandbox.io/) - An amazing in-browser IDE enabling quick prototyping