Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions docs/build/tools/clients/flow-go-sdk/flowkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import (

func main() {
// Load flow.json from the current directory
state, err := flowkit.Load([]string{"flow.json"}, afero.NewOsFs())
state, err := flowkit.Load([]string{"flow.json"}, afero.Afero{Fs: afero.NewOsFs()})
if err != nil {
log.Fatalf("Failed to load project state: %v", err)
}
Expand All @@ -87,7 +87,7 @@ If you need to create a new project from scratch:

```go
// Initialize an empty state
state, err := flowkit.Init(afero.NewOsFs())
state, err := flowkit.Init(afero.Afero{Fs: afero.NewOsFs()})
if err != nil {
log.Fatalf("Failed to initialize state: %v", err)
}
Expand Down Expand Up @@ -131,9 +131,8 @@ log.Printf("Contract: %s\n", contract.Name)
log.Printf("Location: %s\n", contract.Location)

// Get all contract names
names := state.Contracts().Names()
for _, name := range names {
log.Printf("Available contract: %s\n", name)
for _, c := range *state.Contracts() {
log.Printf("Available contract: %s\n", c.Name)
}
```

Expand Down Expand Up @@ -198,6 +197,8 @@ log.Printf("Host: %s\n", testnet.Host)
### Adding or Updating Networks

```go
import "github.com/onflow/flowkit/v2/config"

// Add a custom network
networks := state.Networks()
networks.AddOrUpdate(config.Network{
Expand All @@ -217,6 +218,8 @@ if err != nil {
Network aliases map contract names/locations to their deployed addresses on specific networks:

```go
import "github.com/onflow/flowkit/v2/config"

// Get aliases for testnet
aliases := state.AliasesForNetwork(config.TestnetNetwork)

Expand All @@ -236,6 +239,7 @@ When you have a Cadence program with imports like `import "Kibble"`, you need to

```go
import "github.com/onflow/flowkit/v2/project"
import "github.com/onflow/flowkit/v2/config"

// Get contracts for your target network
contracts, err := state.DeploymentContractsByNetwork(config.TestnetNetwork)
Expand All @@ -258,7 +262,10 @@ transaction {
}
`)

program := project.NewProgram(code, []string{}, "")
program, err := project.NewProgram(code, nil, "")
if err != nil {
log.Fatalf("Failed to parse program: %v", err)
}

// Replace imports with deployed addresses
resolvedProgram, err := importReplacer.Replace(program)
Expand All @@ -276,7 +283,7 @@ The most common pattern is to use network-specific aliases from your project sta

```go
// Load project state and get network-specific contracts and aliases
state, err := flowkit.Load([]string{"flow.json"}, afero.NewOsFs())
state, err := flowkit.Load([]string{"flow.json"}, afero.Afero{Fs: afero.NewOsFs()})
if err != nil {
log.Fatal(err)
}
Expand All @@ -297,7 +304,10 @@ importReplacer := project.NewImportReplacer(
)

// Parse and resolve your program
program := project.NewProgram(scriptCode, []string{}, "script.cdc")
program, err := project.NewProgram(scriptCode, nil, "script.cdc")
if err != nil {
log.Fatalf("Failed to parse program: %v", err)
}
resolvedProgram, err := importReplacer.Replace(program)
if err != nil {
log.Fatalf("Failed to resolve imports: %v", err)
Expand All @@ -314,6 +324,8 @@ Accounts represent Flow blockchain accounts used for signing transactions and de
### Getting Account Information

```go
import "github.com/onflow/flow-go-sdk"

accounts := state.Accounts()

// Get account by name
Expand All @@ -334,6 +346,9 @@ for _, name := range names {
// Get account by address
addr := flow.HexToAddress("0xf8d6e0586b0a20c7")
account, err = accounts.ByAddress(addr)
if err != nil {
log.Fatalf("Account not found by address: %v", err)
}
```

### Getting the Emulator Service Account
Expand Down Expand Up @@ -385,7 +400,6 @@ Here's a complete example that ties everything together:
package main

import (
"context"
"log"

"github.com/onflow/flowkit/v2"
Expand All @@ -396,7 +410,7 @@ import (

func main() {
// 1. Load project state
state, err := flowkit.Load([]string{"flow.json"}, afero.NewOsFs())
state, err := flowkit.Load([]string{"flow.json"}, afero.Afero{Fs: afero.NewOsFs()})
if err != nil {
log.Fatalf("Failed to load state: %v", err)
}
Expand Down Expand Up @@ -433,7 +447,10 @@ func main() {
}
`)

program := project.NewProgram(scriptCode, []string{}, "script.cdc")
program, err := project.NewProgram(scriptCode, nil, "script.cdc")
if err != nil {
log.Fatalf("Failed to parse program: %v", err)
}
resolvedProgram, err := importReplacer.Replace(program)
if err != nil {
log.Fatalf("Failed to resolve imports: %v", err)
Expand Down