How to Create Multiple Accounts in the Flow Emulator

FullstackPho
2 min readJan 6, 2022

Introduction

The Flow blockchain, which uses Cadence as its programming language, is becoming hugely popular for blockchain developers for a huge range of reasons. Everyday we see new faces in the Discord community, so if you are not yet a member, join the official Flow server and come hang out! (https://discord.gg/rVMvjXvhF6)

We also have a useful learning resource that you should check out, it’s called Get The Flow Down and is a compiled list of tutorials, articles, blogs, and anything else that might be helpful when learning Flow! Find it here: https://github.com/ph0ph0/Get-The-Flow-Down

The Flow emulator is very useful for quickly testing and iterating on smart contracts before you deploy them to testnet. Oftentimes, you will need to test the exchange of assets between accounts. For example, Account A purchases an NFT from Account B, and the NFT moves from A to B. In order to do this, you will need more than one emulator account. This short document will describe how to do this.

Creating Accounts

In order to create additional accounts, you will need the Flow CLI installed and the flow.json file present in your project.

If you haven’t installed the Flow CLI, visit the documentation to find out how (https://docs.onflow.org/flow-cli/).

If you haven’t yet initialised Flow in your project, you’ll need to run flow init from your terminal within your project folder. This will create a flow.json file.

Now you run the emulator by running flow emulator -v in your terminal.

Open a new terminal window and follow these steps:

  1. Run flow keys generate` in the terminal. This will generate a private and public key pair. You’ll need these in a second.
  2. run flow accounts create --key YOUR_PUBLIC_KEY in the terminal. Paste your public key after —-key and this will create the account.
  3. In the terminal, you should now see your private key, public key, and the address for the new account. Update the accounts property of the flow.json file so that it looks like this:
...
"accounts": {
"emulator-account": {...},"emulator-account-2": {"address": "ADDRESS_FROM_TERMINAL","key": "PRIVATE_KEY_FROM_TERMINAL"},

And that’s all there is to it! If you would like to use this new account to sign transactions, append --signer emulator-account-2 to your terminal command!

’Til next time :)

--

--

FullstackPho

Specialising in full stack development, blockchain, algo trading and nascent tech. Contact me on Twitter or at fullstackpho@protonmail.com