Skip to content

Commit

Permalink
update cycles wallet doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jessiemongeon1 committed Nov 13, 2023
1 parent 49debbb commit 6be368d
Showing 1 changed file with 106 additions and 41 deletions.
147 changes: 106 additions & 41 deletions docs/developer-docs/setup/cycles/cycles-wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,107 @@ A principal assigned to the **custodian** role can only perform a subset of cycl

Authorizing a principal as a custodian does not automatically grant the principal access to a cycles wallet. The identity assigned to the custodian role must also be assigned a cycles wallet principal. For example, if you authorize the identity `alice_custodian` as a custodian of a cycles wallet (`rwlgt-iiaaa-aaaaa-aaaaa-cai`) in a local project, that user would also need to be assigned to use that wallet with the `dfx identity set-wallet rwlgt-iiaaa-aaaaa-aaaaa-cai` command.

## Create a cycles wallet
## Creating a cycles wallet

If you are doing local development, your cycles wallet is created when you register a new canister principal using `dfx canister create` or when you register, build, and deploy a canister with `dfx deploy`.
### Creating a local cycles wallet

If you are deploying on the Internet Computer mainnet, you typically create your cycles wallet by converting ICP tokens to cycles, transferring the cycles to a new canister principal, and updating the canister with the default cycles wallet WebAssembly module (WASM). [Convert ICP to cycles](/developer-docs/setup/deploy-mainnet.md#creating-a-cycles-wallet) shows how to do this.
If you are doing local development, your local cycles wallet is created when you register a new canister principal using `dfx canister create` or when you register, build, and deploy a canister with `dfx deploy`.

There are dapps that can help you convert ICP to cycles and create a new cycles wallet, e.g., [NNS dapp](../../../tokenomics/token-holders/nns-app-quickstart#_deploy_a_canister_with_cycles).
Alternatively, a local instance of the cycles wallet can be deployed manually with the following workflow:

## Check the cycle balance
- #### Step 1: Clone the cycles wallet repository and navigate into the directory:

In the local canister execution environment or with a cycles wallet on the Internet Computer, you can use the:
```
git clone https://github.com/dfinity/cycles-wallet.git
cd cycles-wallet
```

- #### Step 2: Install the dependencies with the command:

```
dfx wallet balance
npm ci
```

- #### Step 3: Start a local replica if one is not already running:

```
dfx start --background --clean
```

- #### Step 4: Deploy the cycles wallet canister locally:

```
dfx deploy
```

or
- #### Step 5: Get the canister ID of the cycles wallet:

```
wallet_balance
dfx canister id wallet
```

- #### Step 6: Open the wallet's Candid UI at the URL

```
http://localhost:8000/?canisterId=<wallet_canister_id_here>&identityProvider=http://localhost:8000/?canisterId=<internet_identity_id>
```

### Creating a cycles wallet on the mainnet

If you are deploying on the Internet Computer mainnet, you typically create your cycles wallet by converting ICP tokens to cycles, transferring the cycles to a new canister principal, and updating the canister with the default cycles wallet WebAssembly module (Wasm).

There are dapps that can help you convert ICP to cycles and create a new cycles wallet, e.g., [NNS dapp](../../../tokenomics/token-holders/nns-app-quickstart#_deploy_a_canister_with_cycles).

- #### Step 1: Create a new canister with cycles by transferring ICP tokens from your ledger account. You can do so by running a command similar to the following:

dfx ledger --network ic create-canister <principal-identifier> --amount <icp-tokens>

This command converts the number of ICP tokens you specify for the `--amount` argument into cycles, and associates the cycles with a new canister identifier controlled by the principal you specify.

For example, the following command converts .25 ICP tokens into cycles and specifies the principal identifier for the default identity as the controller of the new canister:

dfx ledger --network ic create-canister tsqwz-udeik-5migd-ehrev-pvoqv-szx2g-akh5s-fkyqc-zy6q7-snav6-uqe --amount .25

If the transaction is successful, the ledger records the event and you should see output similar to the following:

Transfer sent at BlockHeight: 20
Canister created with id: "gastn-uqaaa-aaaae-aaafq-cai"

- #### Step 2: Install the cycles wallet code in the newly-created canister ID by running a command similar to the following:

dfx identity --network ic deploy-wallet <canister-identifier>

For example:

dfx identity --network ic deploy-wallet gastn-uqaaa-aaaae-aaafq-cai

This command displays output similar to the following:

Creating a wallet canister on the IC network.
The wallet canister on the "ic" network for user "default" is "gastn-uqaaa-aaaae-aaafq-cai"

## Listing wallets

You can use the following command to display the wallet's principal and role (contact, custodian, or controller). If the wallet has a name or a kind associated with it, this information will be returned from the following command as well:

```
dfx wallet addresses
```

commands to check the current cycle balance.
This command displays output similar to the following:

```
Id: hoqq7-3eo6j-dee4s-aiabk-6rqxw-kwgyo-rhru7-bdgmk-k5ipv-chkhx-cqe, Kind: Unknown, Role: Controller, Name: No name set.
```


## Check the cycle balance

In the local canister execution environment or with a cycles wallet on the Internet Computer, you can use the following command to check the current cycles balance:

```
dfx wallet balance
```

### Check your cycles balance when developing locally

Expand All @@ -111,25 +188,25 @@ To check the cycles balance in a local project:

### Check the cycles balance when deploying on the mainnet

If you have deployed a cycles wallet on the Internet Computer, you can use the `dfx wallet balance` command to check the current cycles balance on the network.
If you have deployed a cycles wallet on the mainnet, you can use the `dfx wallet balance --network ic` command to check the current cycles balance on the network.

To check the cycles balance on the Internet Computer:
To check the cycles balance on the mainnet:

- #### Step 1: Open a terminal and navigate to a directory that contains a `dfx.json` configuration file.

- #### Step 2: Check your connection to the Internet Computer by running the following command:
- #### Step 2: Check your connection to the mainnet by running the following command:

dfx ping ic

- #### Step 3: Display the cycle balance from the cycles wallet associated with the currently-selected identity by running the following command:

dfx wallet --network ic balance
dfx wallet balance --network ic

The command displays output similar to the following:

67.992 TC (trillion cycles).

#### Call the cycles `wallet_balance` method
### Call the cycles `wallet_balance` method

You can also check the cycles balance by calling the `wallet_balance` method in the cycles wallet canister directly. For example, if your principal is a controller for the `h5aet-waaaa-aaaab-qaamq-cai` cycles wallet, you can check the current cycle balance by running the following command:

Expand All @@ -139,18 +216,6 @@ The command returns the balance using Candid format as a record with an amount f

(record { 3_573_748_184 = 6_895_656_625_450 })

command to create a cycles wallet canister tied to an identity. You can use `dfx wallet` commands to modify your cycles wallet settings, send cycles to other cycles wallets, and add or remove controllers and custodians.

## Listing wallets

You can use the:

```
dfx wallet addresses
```

command to display the wallet's principal and role (contact, custodian, or controller), and might contain a name, and kind (unknown, user, or canister) associated with the address.

## Using your wallet

After you have used the `dfx identity deploy-wallet` command to create a cycles wallet canister tied to an identity, you can use `dfx wallet` commands to modify your cycles wallet settings, send cycles to other cycles wallets, and add or remove controllers and custodians.
Expand All @@ -175,20 +240,20 @@ dfx wallet send --help

For reference information and examples that illustrate using dfx wallet commands, select an appropriate command.

- `add-controller`: add a controller using the selected identity's principal.
- `addresses`: displays the address book of the cycles wallet.
- `authorize`: authorize a custodian by principal for the selected identity's cycles wallet
- `balance`: displays the cycles wallet balance of the selected identity.
- `controllers`: displays a list of the selected identity's cycles wallet controllers.
- `custodians`: displays a list of the selected identity's cycles wallet custodians.
- `deauthorize`: deauthorize a cycles wallet custodian using the custodian's principal.
- `help`: displays a usage message and the help of the given subcommand(s).
- `name`: returns the name of the cycles wallet if you've used the dfx wallet set-name command.
- `redeem-faucet-coupon`: redeem a code at the cycles faucet.
- `remove-controller`: removes a specified controller from the selected identity's cycles wallet.
- `send`: sends a specified amount of cycles from the selected identity's cycles wallet to another cycles wallet using the destination wallet canister ID.
- `set-name`: specify a name for your cycles wallet.
- `upgrade`: upgrade the cycles wallet's Wasm module to the current Wasm bundled with DFX.
- [`add-controller`](/docs/current/references/cli-reference/dfx-wallet#dfx-wallet-add-controller): add a controller using the selected identity's principal.
- [`addresses`](/docs/current/references/cli-reference/dfx-wallet#dfx-wallet-addresses): displays the address book of the cycles wallet.
- [`authorize`](/docs/current/references/cli-reference/dfx-wallet#dfx-wallet-authorize): authorize a custodian by principal for the selected identity's cycles wallet
- [`balance`](/docs/current/references/cli-reference/dfx-wallet#dfx-wallet-balance): displays the cycles wallet balance of the selected identity.
- [`controllers`](/docs/current/references/cli-reference/dfx-wallet#dfx-wallet-controllers): displays a list of the selected identity's cycles wallet controllers.
- [`custodians`](/docs/current/references/cli-reference/dfx-wallet#dfx-wallet-custodians): displays a list of the selected identity's cycles wallet custodians.
- [`deauthorize`](/docs/current/references/cli-reference/dfx-wallet#dfx-wallet-deauthorize): deauthorize a cycles wallet custodian using the custodian's principal.
- [`help`](/docs/current/references/cli-reference/dfx-wallet#dfx-wallet-help): displays a usage message and the help of the given subcommand(s).
- [`name`](/docs/current/references/cli-reference/dfx-wallet#dfx-wallet-name): returns the name of the cycles wallet if you've used the dfx wallet set-name command.
- [`redeem-faucet-coupon`](/docs/current/references/cli-reference/dfx-wallet#dfx-wallet-redeem-faucet-coupon): redeem a code at the cycles faucet.
- [`remove-controller`](/docs/current/references/cli-reference/dfx-wallet#remove-controller): removes a specified controller from the selected identity's cycles wallet.
- [`send`](/docs/current/references/cli-reference/dfx-wallet#send): sends a specified amount of cycles from the selected identity's cycles wallet to another cycles wallet using the destination wallet canister ID.
- [`set-name`](/docs/current/references/cli-reference/dfx-wallet#set-name): specify a name for your cycles wallet.
- [`upgrade`](/docs/current/references/cli-reference/dfx-wallet#upgrade): upgrade the cycles wallet's Wasm module to the current Wasm bundled with DFX.

### Adding a controller
An identity assigned the role of controller has the most privileges and can perform the following actions on the selected identity's cycles wallet. Identities that are added as controllers are also listed as custodians.
Expand Down

0 comments on commit 6be368d

Please sign in to comment.