
Go with the Flow
Tooling to help develop application on the the Flow Blockchain
Set of go scripts to make it easer to run a story consisting of creating accounts,
deploying contracts, executing transactions and running scripts on the Flow Blockchain.
These go scripts also make writing integration tests of your smart contracts much easier.
Main features
- Create a single go file that will start emulator, deploy contracts, create accounts and run scripts and transactions. see
examples/demo/main.go
- Fetch events, store progress in a file and send results to Discord. see
examples/event/main.go
- Support inline scripts if you do not want to store everything in a file when testing
- Supports writing tests against transactions and scripts with some limitations on how to implement them.
- Asserts to make it easier to use the library in writing tests see
examples/transaction_test.go
for examples
Gotchas
- When specifying extra accounts that are created on emulator they are created in alphabetical order, the addresses the emulator assign is always fixed.
- tldr; Name your stakeholder accounts in alphabetical order
- When writing integration tests, tests must be in the same folder as flow.json
with contracts and transactions/scripts in subdirectories in order for the path resolver
to work correctly
Note on v2
v2 of GoWithTheFlow removed a lot of the code in favor of flowkit
in the flow-cli. Some of the code from here was
contributed by me into flow-cli like the goroutine based event fetcher.
Breaking changes between v1 and v2:
- v1 had a config section for discord webhooks. That has been removed since the flow-cli will remove extra config things in flow.json. Store the webhook url in an env variable and use it as argument when creating the DiscordWebhook struct.
Special thanks to @sideninja for helping me get my changes into flow-cli. and for jayShen that helped with fixing some issues!
Resources
- Run the demo example in this project with
cd example && make
. The emulator will be run in memory.
- Check other codebases that use this project
- Feel free to ask questions to @bjartek in the Flow Discord.
Usage
First create a project directory, initialize the go module and install go-with-the-flow
:
mkdir test-gwtf && cd test-gtwf
flow init
go mod init example.com/test-gwtf
go get github.com/bjartek/go-with-the-flow/v2/gwtf
Then create a task file:
touch tasks/main.go
In that task file, you can then import go-with-the-flow
and use it to your convenience, for example:
package main
import (
"fmt"
"github.com/bjartek/go-with-the-flow/v2/gwtf"
)
func main() {
g := gwtf.NewGoWithTheFlowInMemoryEmulator()
fmt.Printf("%v", g.State.Accounts())
}
Then you can run
go run ./tasks/main.go
This is a minimal example that only prints accounts, but from there you can branch out.
Credits
This project is a rewrite of https://github.com/versus-flow/go-flow-tooling
Todo
- fix golangci-rules, disabled a bunch to get the build green