The emulator runs a local version of the flow blockchain for developers to use for testing their smart contracts. Whenever you start an instance of the emulator, you have access to all the configuration options and keys.
The FlowToken contract and the FungibleToken contracts are automatically deployed to the emulator on startup, (see emulator addresses here) and minting FLOW is controlled by the Service account, which is also pre-created at startup.
To mint FLOW tokens on the emulator, you can use the Flow Javascript Testing Framework. Here are the steps:
-
Initialize the framework with the init method.
-
Start the emulator using the emulator.start() method.
-
Get the address of the account you want to mint FLOW tokens to. For example, if the account is named "Alice", you can get the address using getAccountAddress("Alice")
-
Specify the amount of FLOW tokens you want to mint and send to the recipient.
-
Use the mintFlow method to mint the specified amount of FLOW and send it to the recipient.
Here is an example of how you can do this:
import {init, emulator, mintFlow} from "@onflow/flow-js-testing"
const main = async () => {
const basePath = path.resolve(__dirname, "../cadence")
await init(basePath)
await emulator.start()
const Alice = await getAccountAddress("Alice")
const amount = "42.0"
const [mintResult, error] = await mintFlow(Alice)
console.log(mintResult, error)
await emulator.stop()
}
main()
Please note that the framework needs to be initialized with the init method for the mintFlow method to work.
For more information, you can refer to the Flow Token Management documentation.