@@ -71,7 +71,7 @@ import (
7171
7272func main () {
7373 // Load flow.json from the current directory
74- state , err := flowkit.Load ([]string {" flow.json" }, afero.NewOsFs ())
74+ state , err := flowkit.Load ([]string {" flow.json" }, afero.Afero {Fs: afero. NewOsFs ()} )
7575 if err != nil {
7676 log.Fatalf (" Failed to load project state: %v " , err)
7777 }
@@ -87,7 +87,7 @@ If you need to create a new project from scratch:
8787
8888``` go
8989// Initialize an empty state
90- state , err := flowkit.Init (afero.NewOsFs ())
90+ state , err := flowkit.Init (afero.Afero {Fs: afero. NewOsFs ()} )
9191if err != nil {
9292 log.Fatalf (" Failed to initialize state: %v " , err)
9393}
@@ -131,9 +131,8 @@ log.Printf("Contract: %s\n", contract.Name)
131131log.Printf (" Location: %s \n " , contract.Location )
132132
133133// Get all contract names
134- names := state.Contracts ().Names ()
135- for _ , name := range names {
136- log.Printf (" Available contract: %s \n " , name)
134+ for _ , c := range *state.Contracts () {
135+ log.Printf (" Available contract: %s \n " , c.Name )
137136}
138137```
139138
@@ -198,6 +197,8 @@ log.Printf("Host: %s\n", testnet.Host)
198197### Adding or Updating Networks
199198
200199``` go
200+ import " github.com/onflow/flowkit/v2/config"
201+
201202// Add a custom network
202203networks := state.Networks ()
203204networks.AddOrUpdate (config.Network {
@@ -217,6 +218,8 @@ if err != nil {
217218Network aliases map contract names/locations to their deployed addresses on specific networks:
218219
219220``` go
221+ import " github.com/onflow/flowkit/v2/config"
222+
220223// Get aliases for testnet
221224aliases := state.AliasesForNetwork (config.TestnetNetwork )
222225
@@ -236,6 +239,7 @@ When you have a Cadence program with imports like `import "Kibble"`, you need to
236239
237240``` go
238241import " github.com/onflow/flowkit/v2/project"
242+ import " github.com/onflow/flowkit/v2/config"
239243
240244// Get contracts for your target network
241245contracts , err := state.DeploymentContractsByNetwork (config.TestnetNetwork )
@@ -258,7 +262,10 @@ transaction {
258262}
259263` )
260264
261- program := project.NewProgram (code, []string {}, " " )
265+ program , err := project.NewProgram (code, nil , " " )
266+ if err != nil {
267+ log.Fatalf (" Failed to parse program: %v " , err)
268+ }
262269
263270// Replace imports with deployed addresses
264271resolvedProgram , err := importReplacer.Replace (program)
@@ -276,7 +283,7 @@ The most common pattern is to use network-specific aliases from your project sta
276283
277284``` go
278285// Load project state and get network-specific contracts and aliases
279- state , err := flowkit.Load ([]string {" flow.json" }, afero.NewOsFs ())
286+ state , err := flowkit.Load ([]string {" flow.json" }, afero.Afero {Fs: afero. NewOsFs ()} )
280287if err != nil {
281288 log.Fatal (err)
282289}
@@ -297,7 +304,10 @@ importReplacer := project.NewImportReplacer(
297304)
298305
299306// Parse and resolve your program
300- program := project.NewProgram (scriptCode, []string {}, " script.cdc" )
307+ program , err := project.NewProgram (scriptCode, nil , " script.cdc" )
308+ if err != nil {
309+ log.Fatalf (" Failed to parse program: %v " , err)
310+ }
301311resolvedProgram , err := importReplacer.Replace (program)
302312if err != nil {
303313 log.Fatalf (" Failed to resolve imports: %v " , err)
@@ -314,6 +324,8 @@ Accounts represent Flow blockchain accounts used for signing transactions and de
314324### Getting Account Information
315325
316326``` go
327+ import " github.com/onflow/flow-go-sdk"
328+
317329accounts := state.Accounts ()
318330
319331// Get account by name
@@ -334,6 +346,9 @@ for _, name := range names {
334346// Get account by address
335347addr := flow.HexToAddress (" 0xf8d6e0586b0a20c7" )
336348account, err = accounts.ByAddress (addr)
349+ if err != nil {
350+ log.Fatalf (" Account not found by address: %v " , err)
351+ }
337352```
338353
339354### Getting the Emulator Service Account
@@ -385,7 +400,6 @@ Here's a complete example that ties everything together:
385400package main
386401
387402import (
388- " context"
389403 " log"
390404
391405 " github.com/onflow/flowkit/v2"
@@ -396,7 +410,7 @@ import (
396410
397411func main () {
398412 // 1. Load project state
399- state , err := flowkit.Load ([]string {" flow.json" }, afero.NewOsFs ())
413+ state , err := flowkit.Load ([]string {" flow.json" }, afero.Afero {Fs: afero. NewOsFs ()} )
400414 if err != nil {
401415 log.Fatalf (" Failed to load state: %v " , err)
402416 }
@@ -433,7 +447,10 @@ func main() {
433447 }
434448 ` )
435449
436- program := project.NewProgram (scriptCode, []string {}, " script.cdc" )
450+ program , err := project.NewProgram (scriptCode, nil , " script.cdc" )
451+ if err != nil {
452+ log.Fatalf (" Failed to parse program: %v " , err)
453+ }
437454 resolvedProgram , err := importReplacer.Replace (program)
438455 if err != nil {
439456 log.Fatalf (" Failed to resolve imports: %v " , err)
0 commit comments