Skip to content

Commit

Permalink
fix env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jessiemongeon1 committed Oct 17, 2024
1 parent 79ec991 commit dd855c2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 103 deletions.
62 changes: 10 additions & 52 deletions docs/developer-docs/defi/tokens/create.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,76 +27,51 @@ To create a new ICRC-1 token, you will need to first download and configure a lo
The initialization arguments of the ICRC-1 ledger are not specified in the [standard](https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-1/README.md). Thus, the arguments defined in this section are dependent on the reference implementation of the ICRC-1 ledger. If you build your own ICRC-1 ledger, you may use different initialization arguments.
:::

To create a token, you will need to export several environmental variables. The full list can be found below:
To create a token, you will need to record several values. The full list can be found below:

#### `PRE_MINTED_TOKENS`

Amount of tokens that are minted during deployment for a specific account. In this tutorial, it will be the `DEFAULT` account.

```
export PRE_MINTED_TOKENS=10_000_000_000
dfx identity use default
export DEFAULT=$(dfx identity get-principal)
echo $(dfx identity get-principal)
```

#### `TRANSFER_FEE`

Fee that users of the ledger will have to pay anytime they want to make a transfer.

```
export TRANSFER_FEE=10_000
```

#### `ARCHIVE_CONTROLLER`

The [controller <GlossaryTooltip>principal</GlossaryTooltip>](/docs/current/developer-docs/defi/cycles/cycles-wallet#controller-and-custodian-roles) of the archive canisters.

```
dfx identity new archive_controller
dfx identity use archive_controller
export ARCHIVE_CONTROLLER=$(dfx identity get-principal)
echo $(dfx identity get-principal)
```

#### `TRIGGER_THRESHOLD`

The number of blocks to archive when the trigger threshold is exceeded.

```
export TRIGGER_THRESHOLD=2000
```

#### `CYCLE_FOR_ARCHIVE_CREATION`

The number of cycles that will be sent to the archive canister when it is created.

```
export CYCLE_FOR_ARCHIVE_CREATION=10000000000000
```

#### `NUM_OF_BLOCK_TO_ARCHIVE`

The number of blocks that will be archived.

```
export NUM_OF_BLOCK_TO_ARCHIVE=1000
```

#### `TOKEN_NAME`

The name of your token.

```
export TOKEN_NAME="My Token"
```

#### `TOKEN_SYMBOL`

The ticker symbol of your new token.

```
export TOKEN_SYMBOL="XMTK"
```

#### `MINTER`

The account of the principal responsible for minting and burning tokens (see the [ICRC-1 specification](https://github.com/dfinity/ICRC-1)). Transfers from the minting account will generate `Mint` transactions, resulting in the creation of new tokens. To mint tokens, the minting account must call the `icrc1_transfer` function, specifying the recipient in the 'to' value.
Expand All @@ -106,7 +81,7 @@ Transfers sent to the minting account will generate `Burn` transactions, destroy
```
dfx identity new minter
dfx identity use minter
export MINTER=$(dfx identity get-principal)
echo $(dfx identity get-principal)
```

#### `FEATURE_FLAGS`
Expand All @@ -115,13 +90,13 @@ A flag for enabling or disabling certain extension standards to the ICRC-1 stand

If you only want to support the ICRC-1 standard, then you can set the flag to `false`. If you want to also support the ICRC-2 standard, set it to `true`.

```
export FEATURE_FLAGS=false
```

## Edit the project's dfx.json file

Next, insert these environment variables into your project's `dfx.json` file as init arguments for your ledger canister:
Replace the existing content in the `dfx.json` with the following, updating the values of `TOKEN_SYMBOL`, `TOKEN_NAME`, `MINTER`, `TRANSFER_FEE`, `DEFAULT_ACCOUNT_ID `PRE_MINTED_TOKENS`, `NUM_OF_BLOCKS_TO_ARCHIVE`, `TRIGGER_THRESHOLD`, and `ARCHIVE_CONTROLLER` with the values obtained in the previous steps:

:::info
`dfx.json` does not support referring to values through environment variables. Values must be hardcoded in plain text.
:::

```json
{
Expand All @@ -130,25 +105,8 @@ Next, insert these environment variables into your project's `dfx.json` file as
"type": "custom",
"candid": "https://raw.githubusercontent.com/dfinity/ic/<REVISION>/rs/ledger_suite/icrc1/ledger/ledger.did",
"wasm": "https://download.dfinity.systems/ic/<REVISION>/canisters/ic-icrc1-ledger.wasm.gz",
"init_arg": "(variant {Init =
record {
     token_symbol = \"$TOKEN_SYMBOL\";
     token_name = \"$TOKEN_NAME\";
     minting_account = record { owner = principal \"$MINTER\" };
     transfer_fee = $TRANSFER_FEE;
     metadata = vec {};
     feature_flags = opt record{icrc2 = ${FEATURE_FLAGS}};
     initial_balances = vec { record { record { owner = principal \"$DEFAULT\"; }; \"$PRE_MINTED_TOKENS\"; }; };
     archive_options = record {
         num_blocks_to_archive = \"$NUM_OF_BLOCK_TO_ARCHIVE\";
         trigger_threshold = \"$TRIGGER_THRESHOLD\";
         controller_id = principal \"$ARCHIVE_CONTROLLER\";
         cycles_for_archive_creation = opt \"$CYCLE_FOR_ARCHIVE_CREATION\";
     };
 }
})"
"init_arg": "(variant {Init = record { token_symbol = "TOKEN_SYMBOL"; token_name = "TOKEN_NAME"; minting_account = record { owner = principal "MINTER" transfer_fee = TRANSFER_FEE; metadata = vec {}; feature_flags = opt record{icrc2 = false}; initial_balances = vec { record { record { owner = principal "DEFAULT_ACCOUNT_ID"; }; "PRE_MINTED_TOKENS"; }; }; archive_options = record { num_blocks_to_archive = "NUM_OF_BLOCK_TO_ARCHIVE"; trigger_threshold = "TRIGGER_THRESHOLD"; controller_id = principal "ARCHIVE_CONTROLLER"; cycles_for_archive_creation = opt "10000000000000"; }; }} })" },
},
},
"defaults": {
"build": {
"args": "",
Expand Down
35 changes: 12 additions & 23 deletions docs/developer-docs/defi/tokens/ledger/setup/icp_ledger_setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,29 @@ chmod +x download_latest_icp_ledger.sh
``` sh
dfx identity new minter
dfx identity use minter
export MINTER_ACCOUNT_ID=$(dfx ledger account-id)
echo $(dfx ledger account-id)
```

Record the output of these commands as your minting account ID.

Transfers from the minting account will create `Mint` transactions. Transfers to the minting account will create `Burn` transactions.

### Step 5: Switch back to your default identity and record its ledger account identifier.

``` sh
dfx identity use default
export DEFAULT_ACCOUNT_ID=$(dfx ledger account-id)
echo $(dfx ledger account-id)
```

Record the output of these commands as your default account ID.

### Step 6: Configure the `dfx.json` file.

Open the `dfx.json` file in your project's directory. Replace the existing content with the following:
Open the `dfx.json` file in your project's directory. Replace the existing content with the following, updating the values of `MINTER_ACCOUNT_ID` and `DEFAULT_ACCOUNT_ID` with the values obtained in the previous steps:

:::info
`dfx.json` does not support referring to values through environment variables. Values must be hardcoded in plain text.
:::

``` json
{
Expand All @@ -127,26 +135,7 @@ Open the `dfx.json` file in your project's directory. Replace the existing conte
"ic": "ryjl3-tyaaa-aaaaa-aaaba-cai"
}
},
"init_arg": "(variant {
Init = record {
minting_account = \"$MINTER_ACCOUNT_ID\";
initial_values = vec {
record {
\"$DEFAULT_ACCOUNT_ID\";
record {
e8s = 10_000_000_000 : nat64;
};
};
};
send_whitelist = vec {};
transfer_fee = opt record {
e8s = 10_000 : nat64;
};
token_symbol = opt \"LICP\";
token_name = opt \"Local ICP\";
}
})
"
"init_arg" : "(variant { Init = record { minting_account = "MINTER_ACCOUNT_ID"; initial_values = vec { record { "DEFAULT_ACCOUNT_ID"; record { e8s = 10_000_000_000 : nat64; }; }; }; send_whitelist = vec {}; transfer_fee = opt record { e8s = 10_000 : nat64; }; token_symbol = opt \"LICP\"; token_name = opt \"Local ICP\"; } })"
}
},
"defaults": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,29 @@ dfx canister install icp_ledger_canister --argument
Alternatively, you can pass these arguments to the canister directly in the `dfx.json` file:

```json
"canisters": {
"icp_ledger": {
{
"canisters": {
"icp_ledger_canister": {
"type": "custom",
"candid": "https://raw.githubusercontent.com/dfinity/ic/ec35ebd252d4ffb151d2cfceba3a86c4fb87c6d6/rs/rosetta-api/icp_ledger/ledger.did",
"wasm": "https://download.dfinity.systems/ic/ec35ebd252d4ffb151d2cfceba3a86c4fb87c6d6/canisters/ledger-canister.wasm.gz",
"candid": "https://raw.githubusercontent.com/dfinity/ic/d87954601e4b22972899e9957e800406a0a6b929/rs/rosetta-api/icp_ledger/ledger.did",
"wasm": "https://download.dfinity.systems/ic/d87954601e4b22972899e9957e800406a0a6b929/canisters/ledger-canister.wasm.gz",
"remote": {
"id": {
"ic": "ryjl3-tyaaa-aaaaa-aaaba-cai"
}
},
"init_arg": "(variant {
Init = record {
minting_account = \"$MINTER_ACCOUNT_ID\";
initial_values = vec {
record {
\"$DEFAULT_ACCOUNT_ID\";
record {
e8s = 10_000_000_000 : nat64;
};
};
};
send_whitelist = vec {};
transfer_fee = opt record {
e8s = 10_000 : nat64;
};
token_symbol = opt \"LICP\";
token_name = opt \"Local ICP\";
"init_arg" : "(variant { Init = record { minting_account = "MINTER_ACCOUNT_ID"; initial_values = vec { record { "DEFAULT_ACCOUNT_ID"; record { e8s = 10_000_000_000 : nat64; }; }; }; send_whitelist = vec {}; transfer_fee = opt record { e8s = 10_000 : nat64; }; token_symbol = opt \"LICP\"; token_name = opt \"Local ICP\"; } })"
}
})
"
},
...
},
"defaults": {
"build": {
"args": "",
"packtool": ""
}
},
"output_env_file": ".env",
"version": 1
}
```

## Using an `init_arg_file`
Expand All @@ -100,10 +91,10 @@ An example initialization argument file can be found below:
```did
(variant {
Init = record {
minting_account = "xxxxxxxxxx";
minting_account = "MINTER_ACCOUNT_ID";
initial_values = vec {
record {
"xxxxxxxxxx";
"DEFAULT_ACCOUNT_ID";
record {
e8s = 10_000_000_000 : nat64;
};
Expand Down Expand Up @@ -145,4 +136,4 @@ You can also specify the `init_arg_file` for each canister in the `dfx.json` fil

- Initialization arguments must be set individually for each canister, either through the CLI for `dfx.json`. To make this easier, `init_arg_file`s can be used, as detailed below.

- When using an argument file, values referenced as environment variables within the file will not be passed to the canister.
- When using `dfx.json` or an argument file, values referenced as environment variables within the file will not be passed to the canister.

0 comments on commit dd855c2

Please sign in to comment.