-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #467 from onflow/feature/dev-wallet
Integrate Dev Wallet
- Loading branch information
Showing
5 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |