Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions cmd/flow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/onflow/flow-cli/internal/signatures"
"github.com/onflow/flow-cli/internal/snapshot"
"github.com/onflow/flow-cli/internal/status"
"github.com/onflow/flow-cli/internal/tools"
"github.com/onflow/flow-cli/internal/transactions"
"github.com/onflow/flow-cli/internal/version"
"github.com/onflow/flow-cli/pkg/flowkit/util"
Expand All @@ -53,7 +54,10 @@ func main() {
quick.InitCommand.AddToParent(cmd)
quick.DeployCommand.AddToParent(cmd)
quick.RunCommand.AddToParent(cmd)

// single commands
status.Command.AddToParent(cmd)
tools.DevWallet.AddToParent(cmd)

// structured commands
cmd.AddCommand(cadence.Cmd)
Expand Down
71 changes: 71 additions & 0 deletions docs/tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: Start Development Tools with the Flow CLI
sidebar_title: Development Tools
description: How to start development tools using the Flow CLI
---

The Flow CLI integrates different development tools, which can now be easily started
and managed from a single place.

Currently the CLI supports starting:
- [FCL Development Wallet](https://github.com/onflow/fcl-dev-wallet)


## FCL Development Wallet

The FCL dev wallet is a mock Flow wallet that simulates the protocols used by FCL to interact with the Flow blockchain on behalf of simulated user accounts.

**Be sure you have the emulator running before starting this command**
_You can start it using the `flow emulator` command_.

```shell
flow dev-wallet
```
_⚠️ This project implements an FCL compatible
interface, but should **not** be used as a reference for
building a production grade wallet._

After starting dev-wallet, you can set your fcl config to use it like below:

```javascript
import * as fcl from "@onflow/fcl"

fcl.config()
// Point App at Emulator
.put("accessNode.api", "http://localhost:8080")
// Point FCL at dev-wallet (default port)
.put("discovery.wallet", "http://localhost:8701/fcl/authn")
```
You can read more about setting up dev-wallet at [FCL Dev Wallet Project](https://github.com/onflow/fcl-dev-wallet)


## Flags

### Port

- Flag: `--port`
- Valid inputs: Number
- Default: `8701`

Port on which the dev wallet server will listen on.

### Emulator Port

- Flag: `--emulator-port`
- Valid inputs: Number

Port on which the emulator is listening on.

### Configuration

- Flag: `--config-path`
- Short Flag: `-f`
- Valid inputs: valid filename

Specify a filename for the configuration files, you can provide multiple configuration
files by using `-f` flag multiple times.





3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ require (
github.com/manifoldco/promptui v0.9.0
github.com/onflow/cadence v0.23.0
github.com/onflow/cadence/languageserver v0.18.3-0.20220202133308-207188a51831
github.com/onflow/fcl-dev-wallet v0.4.0
github.com/onflow/flow-core-contracts/lib/go/templates v0.10.1
github.com/onflow/flow-emulator v0.29.0
github.com/onflow/flow-emulator v0.30.0
github.com/onflow/flow-go v0.23.2-0.20220304145234-bf10d55c40fa
github.com/onflow/flow-go-sdk v0.24.0
github.com/psiemens/sconfig v0.1.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,8 @@ github.com/onflow/cadence/languageserver v0.16.0/go.mod h1:UPV1so9LcMrhj27IegrTu
github.com/onflow/cadence/languageserver v0.18.2/go.mod h1:ehuDCUevEEavUzgJqLevcZPjfmTzMBX7Sglbi5ur9uU=
github.com/onflow/cadence/languageserver v0.18.3-0.20220202133308-207188a51831 h1:89apbCF/MbTL5ldqYKvwnt8OLN+NuCkdMMJN5clEgrE=
github.com/onflow/cadence/languageserver v0.18.3-0.20220202133308-207188a51831/go.mod h1:sOABh+6LBUWgY6r5iYhu98mDgfiBVTXAKVYHPQV/nvo=
github.com/onflow/fcl-dev-wallet v0.4.0 h1:lmjp4tO57m2LCbJ0P79u4BxpGca8bcFtBJrmtxV39LY=
github.com/onflow/fcl-dev-wallet v0.4.0/go.mod h1:xWVEyGZgdDt4/+PLSlpuqhtzobjnWy5giceIGoErPzs=
github.com/onflow/flow v0.2.3-0.20220131193101-d4e2ca43a621 h1:owMor9/wFpw3fua47UkUeDaFwyySK/dIPiNCCyhoO7c=
github.com/onflow/flow v0.2.3-0.20220131193101-d4e2ca43a621/go.mod h1:lzyAYmbu1HfkZ9cfnL5/sjrrsnJiUU8fRL26CqLP7+c=
github.com/onflow/flow-cli v0.20.3-0.20210512000809-474effb7e7db/go.mod h1:Yh4dgrNiZdXhbU+3UVUmo4gRM0TEBVvhW4ITKVo82dg=
Expand All @@ -1422,8 +1424,8 @@ github.com/onflow/flow-emulator v0.19.0/go.mod h1:k5un51XlFJavboagCqTxd6x8Gle7lx
github.com/onflow/flow-emulator v0.20.3/go.mod h1:xNdVsrMJiAaYJ59Dwo+xvj0ENdvk/bI14zkGN4V0ozs=
github.com/onflow/flow-emulator v0.21.0/go.mod h1:/2dNG6K4fKtpZsazdIeK8Fs0IWXUzqvO3qK5467pYsc=
github.com/onflow/flow-emulator v0.28.1-0.20220202131242-21a2c6e3eac7/go.mod h1:75iLaCkteYi8VsRnPH7RC9jeKjOIXogFq4TkPU71r1c=
github.com/onflow/flow-emulator v0.29.0 h1:YfTLD5mC/0mpwOkPu7pWx66EpwuMCseeYaWHuNnVCGQ=
github.com/onflow/flow-emulator v0.29.0/go.mod h1:jhun5qkwgdkJnmJpG6ghNKbSMfPWZPDSMWhNzqCTuDA=
github.com/onflow/flow-emulator v0.30.0 h1:czxxhtFWv5wYUiNG1KXWuwXrx2JaIHE+yDBsDKGSsuU=
github.com/onflow/flow-emulator v0.30.0/go.mod h1:jhun5qkwgdkJnmJpG6ghNKbSMfPWZPDSMWhNzqCTuDA=
github.com/onflow/flow-ft/lib/go/contracts v0.5.0 h1:Cg4gHGVblxcejfNNG5Mfj98Wf4zbY76O0Y28QB0766A=
github.com/onflow/flow-ft/lib/go/contracts v0.5.0/go.mod h1:1zoTjp1KzNnOPkyqKmWKerUyf0gciw+e6tAEt0Ks3JE=
github.com/onflow/flow-go v0.16.3-0.20210427194927-6050c2a3ae42/go.mod h1:9GUEbBhOGDVf91ZJB6QWqVNQkrM3INEudNyDtIttOu0=
Expand Down
85 changes: 85 additions & 0 deletions internal/tools/wallet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Flow CLI
*
* Copyright 2019-2022 Dapper Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package tools

import (
"fmt"
"strings"

"github.com/onflow/flow-cli/internal/command"
"github.com/onflow/flow-cli/pkg/flowkit"
"github.com/onflow/flow-cli/pkg/flowkit/output"
"github.com/onflow/flow-cli/pkg/flowkit/services"

devWallet "github.com/onflow/fcl-dev-wallet"
"github.com/spf13/cobra"
)

type FlagsWallet struct {
Port uint `default:"8701" flag:"port" info:"Dev wallet port to listen on"`
}

var walletFlags = FlagsWallet{}

var DevWallet = &command.Command{
Cmd: &cobra.Command{
Use: "dev-wallet",
Short: "Starts a dev wallet",
Example: "flow dev-wallet",
Args: cobra.ExactArgs(0),
},
Flags: &walletFlags,
RunS: wallet,
}

func wallet(
_ []string,
_ flowkit.ReaderWriter,
_ command.GlobalFlags,
_ *services.Services,
state *flowkit.State,
) (command.Result, error) {
service, err := state.EmulatorServiceAccount()
if err != nil {
return nil, err
}

key := service.Key().ToConfig()
conf := devWallet.Config{
Address: fmt.Sprintf("0x%s", service.Address().String()),
PrivateKey: strings.TrimPrefix(key.PrivateKey.String(), "0x"),
PublicKey: strings.TrimPrefix(key.PrivateKey.PublicKey().String(), "0x"),
AccessNode: "http://localhost:8080",
}

srv, err := devWallet.NewHTTPServer(walletFlags.Port, &conf)
if err != nil {
return nil, err
}

fmt.Printf("%s Starting dev wallet server on port %d\n", output.SuccessEmoji(), walletFlags.Port)
fmt.Printf("%s Make sure the emulator is running\n", output.WarningEmoji())

err = srv.Start()
if err != nil {
return nil, err
}

return nil, nil
}