diff --git a/blog/news-and-updates/2024-03-06-update.mdx b/blog/news-and-updates/2024-03-06-update.mdx index 4503641e67..1f261dda73 100644 --- a/blog/news-and-updates/2024-03-06-update.mdx +++ b/blog/news-and-updates/2024-03-06-update.mdx @@ -31,7 +31,7 @@ In the newest version of Motoko, the type system has been revised to detect and For example, in previous Motoko versions, the following code snippet could be used: -```motoko +```motoko no-repl func splitCycles() { let amount = ExperimentalCycles.balance() / 2; ExperimentalCycles.add(amount); // new error @@ -47,7 +47,7 @@ In Motoko v0.11.0 and newer, this code will throw a compiler error: To support the new changes, the previous code should be rewritten to include the `system` type parameter: -```motoko +```motoko no-repl func splitCycles() { let amount = ExperimentalCycles.balance() / 2; ExperimentalCycles.add(amount); // warning diff --git a/docs/developer-docs/defi/nfts/nft-collections.mdx b/docs/developer-docs/defi/nfts/nft-collections.mdx index 0e7da893c1..fa08591fcd 100644 --- a/docs/developer-docs/defi/nfts/nft-collections.mdx +++ b/docs/developer-docs/defi/nfts/nft-collections.mdx @@ -87,7 +87,7 @@ dfx canister call icrc7 init This command will initialize an NFT collection using the parameters set in the project's `example/initial_state/icrc7.mo` file: -```motoko +```motoko no-repl import ICRC7 "mo:icrc7-mo"; module{ diff --git a/docs/developer-docs/multi-chain/bitcoin/using-btc/create-transactions.mdx b/docs/developer-docs/multi-chain/bitcoin/using-btc/create-transactions.mdx index ccb2d3b2b5..c5d6711326 100644 --- a/docs/developer-docs/multi-chain/bitcoin/using-btc/create-transactions.mdx +++ b/docs/developer-docs/multi-chain/bitcoin/using-btc/create-transactions.mdx @@ -34,7 +34,7 @@ can have multiple UTXOs associated with it. -```motoko +```motoko no-repl let own_utxos = (await BitcoinApi.get_utxos(network, own_address)).utxos; @@ -65,7 +65,7 @@ An UTXO has the following structure: -```motoko +```motoko no-repl /// An unspent transaction output. public type Utxo = { @@ -127,7 +127,7 @@ using the `bitcoin_get_current_fee_percentiles` API endpoint and choosing the -```motoko +```motoko no-repl // Get fee percentiles from previous transactions to estimate our own fee. let fee_percentiles = await BitcoinApi.get_current_fee_percentiles(network); @@ -187,7 +187,7 @@ transaction and requires a signature. -```motoko +```motoko no-repl // Builds a transaction to send the given `amount` of satoshis to the // destination address. diff --git a/docs/developer-docs/multi-chain/bitcoin/using-btc/generate-addresses.mdx b/docs/developer-docs/multi-chain/bitcoin/using-btc/generate-addresses.mdx index 8506ed03ab..03591aec18 100644 --- a/docs/developer-docs/multi-chain/bitcoin/using-btc/generate-addresses.mdx +++ b/docs/developer-docs/multi-chain/bitcoin/using-btc/generate-addresses.mdx @@ -70,7 +70,7 @@ demonstrates how to generate a `P2PKH` address from a canister's public key. -```motoko +```motoko no-repl /// Returns the P2PKH address of this canister at the given derivation path. public func get_p2pkh_address(network : Network, key_name : Text, derivation_path : [[Nat8]]) : async BitcoinAddress { diff --git a/docs/developer-docs/multi-chain/bitcoin/using-btc/read-state.mdx b/docs/developer-docs/multi-chain/bitcoin/using-btc/read-state.mdx index 9743c6b3ed..d4df3954ae 100644 --- a/docs/developer-docs/multi-chain/bitcoin/using-btc/read-state.mdx +++ b/docs/developer-docs/multi-chain/bitcoin/using-btc/read-state.mdx @@ -41,7 +41,7 @@ To read unspent transaction outputs from the Bitcoin network, make a call to the -```motoko +```motoko no-repl type ManagementCanisterActor = actor { bitcoin_get_utxos : GetUtxosRequest -> async GetUtxosResponse; }; @@ -103,7 +103,7 @@ To read the current balance of a Bitcoin address, make a call to the `bitcoin_ge -```motoko +```motoko no-repl type ManagementCanisterActor = actor { bitcoin_get_balance : GetBalanceRequest -> async Satoshi; }; @@ -168,7 +168,7 @@ The function returns 101 numbers that are fees measured in millisatoshi per virt -```motoko +```motoko no-repl type ManagementCanisterActor = actor { bitcoin_get_current_fee_percentiles : GetCurrentFeePercentilesRequest -> async [MillisatoshiPerVByte]; }; diff --git a/docs/developer-docs/multi-chain/bitcoin/using-btc/sign-transactions.mdx b/docs/developer-docs/multi-chain/bitcoin/using-btc/sign-transactions.mdx index 2305535979..7d25a74963 100644 --- a/docs/developer-docs/multi-chain/bitcoin/using-btc/sign-transactions.mdx +++ b/docs/developer-docs/multi-chain/bitcoin/using-btc/sign-transactions.mdx @@ -25,7 +25,7 @@ The following snippet shows a simplified example of how to sign a Bitcoin transa -```motoko +```motoko no-repl public func sign_transaction( own_public_key : [Nat8], own_address : BitcoinAddress, diff --git a/docs/developer-docs/multi-chain/bitcoin/using-btc/submit-transactions.mdx b/docs/developer-docs/multi-chain/bitcoin/using-btc/submit-transactions.mdx index d5f8200231..313b391d92 100644 --- a/docs/developer-docs/multi-chain/bitcoin/using-btc/submit-transactions.mdx +++ b/docs/developer-docs/multi-chain/bitcoin/using-btc/submit-transactions.mdx @@ -23,7 +23,7 @@ The following snippet shows how to send a signed transaction to the Bitcoin netw -```motoko +```motoko no-repl type ManagementCanisterActor = actor { bitcoin_send_transaction : SendTransactionRequest -> async (); }; diff --git a/docs/developer-docs/multi-chain/ethereum/evm-rpc/costs.mdx b/docs/developer-docs/multi-chain/ethereum/evm-rpc/costs.mdx index 1b43939cfe..87450ce0aa 100644 --- a/docs/developer-docs/multi-chain/ethereum/evm-rpc/costs.mdx +++ b/docs/developer-docs/multi-chain/ethereum/evm-rpc/costs.mdx @@ -83,8 +83,7 @@ Once you have determined how many cycles your call will need, you can send them -```motoko - +```motoko no-repl import EvmRpc "canister:evm_rpc"; import Cycles "mo:base/ExperimentalCycles"; diff --git a/docs/developer-docs/multi-chain/ethereum/evm-rpc/evm-rpc-canister.mdx b/docs/developer-docs/multi-chain/ethereum/evm-rpc/evm-rpc-canister.mdx index 341391721c..47f720756a 100644 --- a/docs/developer-docs/multi-chain/ethereum/evm-rpc/evm-rpc-canister.mdx +++ b/docs/developer-docs/multi-chain/ethereum/evm-rpc/evm-rpc-canister.mdx @@ -114,7 +114,7 @@ Note that when deploying your own canister, you may encounter API rate limits. R -```motoko +```motoko no-repl import EvmRpc "canister:evm_rpc"; import Cycles "mo:base/ExperimentalCycles"; @@ -232,7 +232,7 @@ This example use case displays a caveat that comes with mapping the `eth_getLogs -```motoko +```motoko no-repl import EvmRpc "canister:evm_rpc"; import Cycles "mo:base/ExperimentalCycles"; @@ -320,7 +320,7 @@ dfx canister call evm_rpc eth_getBlockByNumber "(variant {$RPC_SOURCE}, $RPC_CON -```motoko +```motoko no-repl import EvmRpc "canister:evm_rpc"; import Cycles "mo:base/ExperimentalCycles"; @@ -487,7 +487,7 @@ pub async fn eth_call( -```motoko +```motoko no-repl import EvmRpc "canister:evm_rpc"; import Cycles "mo:base/ExperimentalCycles"; @@ -587,7 +587,7 @@ dfx canister call evm_rpc eth_getTransactionCount "(variant {$RPC_SOURCE}, $RPC_ -```motoko +```motoko no-repl import EvmRpc "canister:evm_rpc"; import Cycles "mo:base/ExperimentalCycles"; @@ -703,7 +703,7 @@ The EVM RPC canister can also be used to send raw transactions to the Ethereum a -```motoko +```motoko no-repl import EvmRpc "canister:evm_rpc"; import Cycles "mo:base/ExperimentalCycles"; @@ -818,7 +818,7 @@ Note that even if an error is returned, you should assume that your transaction -```motoko +```motoko no-repl import EvmRpc "canister:evm_rpc"; import Cycles "mo:base/ExperimentalCycles"; @@ -909,7 +909,7 @@ dfx canister call evm_rpc request "(variant {$JSON_RPC_SOURCE}, "'"{ \"jsonrpc\" -```motoko +```motoko no-repl let services = #EthMainnet; let config = null; ``` diff --git a/docs/developer-docs/multi-chain/ethereum/using-eth/generating-addresses.mdx b/docs/developer-docs/multi-chain/ethereum/using-eth/generating-addresses.mdx index a1a8fa1036..363003dde6 100644 --- a/docs/developer-docs/multi-chain/ethereum/using-eth/generating-addresses.mdx +++ b/docs/developer-docs/multi-chain/ethereum/using-eth/generating-addresses.mdx @@ -25,31 +25,31 @@ To create an ETH address for your canister, first you will need to obtain an ECD -```motoko - // Declare "ic" to be the management canister, which is evoked by `actor("aaaaa-aa")`.: - let ic : IC = actor("aaaaa-aa"); +```motoko no-repl +// Declare "ic" to be the management canister, which is evoked by `actor("aaaaa-aa")`.: +let ic : IC = actor("aaaaa-aa"); - public shared (msg) func public_key() : async { #Ok : { public_key: Blob }; #Err : Text } { - let caller = Principal.toBlob(msg.caller); +public shared (msg) func public_key() : async { #Ok : { public_key: Blob }; #Err : Text } { + let caller = Principal.toBlob(msg.caller); - try { + try { - // Make a call to the management canister to request an ECDSA public key: - let { public_key } = await ic.ecdsa_public_key({ - canister_id = null; - derivation_path = [ caller ]; - key_id = { curve = #secp256k1; name = "test_key_1" }; - }); + // Make a call to the management canister to request an ECDSA public key: + let { public_key } = await ic.ecdsa_public_key({ + canister_id = null; + derivation_path = [ caller ]; + key_id = { curve = #secp256k1; name = "test_key_1" }; + }); - #Ok({ public_key }) + #Ok({ public_key }) - } catch (err) { + } catch (err) { - #Err(Error.message(err)) + #Err(Error.message(err)) - } + } - }; +}; ``` diff --git a/docs/developer-docs/smart-contracts/advanced-features/handling-get-post-requests.mdx b/docs/developer-docs/smart-contracts/advanced-features/handling-get-post-requests.mdx index ee9677622c..7642c41b42 100644 --- a/docs/developer-docs/smart-contracts/advanced-features/handling-get-post-requests.mdx +++ b/docs/developer-docs/smart-contracts/advanced-features/handling-get-post-requests.mdx @@ -37,7 +37,7 @@ HTTP `GET` requests are used to retrieve and return existing data from an endpoi In Motoko, a `case` configuration can be used to return different `GET` responses based on the endpoint: -```motoko +```motoko no-repl import FHM "mo:StableHashMap/FunctionalStableHashMap"; import SHA256 "mo:motoko-sha/SHA256"; import CertTree "mo:ic-certification/CertTree"; @@ -393,7 +393,7 @@ HTTP `POST` requests are used to send data to an endpoint with the intention of In Motoko, a `case` configuration can be used to return different `POST` responses based on the endpoint: -```motoko +```motoko no-repl import FHM "mo:StableHashMap/FunctionalStableHashMap"; import SHA256 "mo:motoko-sha/SHA256"; import CertTree "mo:ic-certification/CertTree"; diff --git a/docs/developer-docs/smart-contracts/advanced-features/https-outcalls/https-outcalls-get.mdx b/docs/developer-docs/smart-contracts/advanced-features/https-outcalls/https-outcalls-get.mdx index a86e65b91c..fee7d1ddbf 100644 --- a/docs/developer-docs/smart-contracts/advanced-features/https-outcalls/https-outcalls-get.mdx +++ b/docs/developer-docs/smart-contracts/advanced-features/https-outcalls/https-outcalls-get.mdx @@ -54,7 +54,7 @@ Before you dive in, here is the structure of the code you will touch: -```motoko +```motoko no-repl //Import some custom types from `src/backend_canister/Types.mo` file import Types "Types"; @@ -95,7 +95,7 @@ actor { You will also create some custom types in `Types.mo`. It will look like this: -```motoko +```motoko no-repl module Types { //type declarations for s, HTTP responses, management canister, etc... @@ -180,7 +180,7 @@ rustup target add wasm32-unknown-unknown Open the `src/send_http_get_motoko_backend/main.mo` file in a text editor and replace content with: -```motoko title="src/send_http_get_motoko_backend/main.mo" +```motoko no-repl title="src/send_http_get_motoko_backend/main.mo" import Debug "mo:base/Debug"; import Blob "mo:base/Blob"; import Cycles "mo:base/ExperimentalCycles"; @@ -534,7 +534,7 @@ fn transform(raw: TransformArgs) -> HttpResponse { Open the `src/send_http_get_motoko_backend/Types.mo` file in a text editor and replace content with: -```motoko title="src/send_http_get_motoko_backend/Types.mo" +```motoko no-repl title="src/send_http_get_motoko_backend/Types.mo" module Types { public type Timestamp = Nat64; diff --git a/docs/developer-docs/smart-contracts/advanced-features/https-outcalls/https-outcalls-post.mdx b/docs/developer-docs/smart-contracts/advanced-features/https-outcalls/https-outcalls-post.mdx index fcd0b300fc..e3ebaa9c28 100644 --- a/docs/developer-docs/smart-contracts/advanced-features/https-outcalls/https-outcalls-post.mdx +++ b/docs/developer-docs/smart-contracts/advanced-features/https-outcalls/https-outcalls-post.mdx @@ -62,7 +62,7 @@ Before you dive in, here is the structure of the code you will touch: -```motoko +```motoko no-repl //Import some custom types from `src/backend_canister/Types.mo` file import Types "Types"; @@ -97,7 +97,7 @@ actor { You will also create some custom types in `Types.mo`. This will look like this: -```motoko +```motoko no-repl module Types { //type declarations for HTTP requests, HTTP responses, management canister, etc... @@ -176,7 +176,7 @@ rustup target add wasm32-unknown-unknown Open the `src/send_http_post_motoko_backend/main.mo` file in a text editor and replace content with: -```motoko title="src/send_http_post_motoko_backend/main.mo" +```motoko no-repl title="src/send_http_post_motoko_backend/main.mo" import Debug "mo:base/Debug"; import Blob "mo:base/Blob"; import Cycles "mo:base/ExperimentalCycles"; @@ -531,7 +531,7 @@ fn transform(raw: TransformArgs) -> HttpResponse { Create the `src/send_http_post_motoko_backend/Types.mo` file in a text editor and replace content with: -```motoko title="src/send_http_post_motoko_backend/Types.mo" +```motoko no-repl title="src/send_http_post_motoko_backend/Types.mo" module Types { //1. Type that describes the Request arguments for an HTTPS outcall diff --git a/docs/developer-docs/smart-contracts/advanced-features/management-canister.mdx b/docs/developer-docs/smart-contracts/advanced-features/management-canister.mdx index ab64f6f27d..c17a87a8c9 100644 --- a/docs/developer-docs/smart-contracts/advanced-features/management-canister.mdx +++ b/docs/developer-docs/smart-contracts/advanced-features/management-canister.mdx @@ -49,7 +49,7 @@ Here are some examples calling the management canister: -```motoko +```motoko no-repl actor { let ic = actor "aaaaa-aa" : IC.Self; public func createCanister(settings: ?canister_settings) : async () { diff --git a/docs/developer-docs/smart-contracts/advanced-features/periodic-tasks.mdx b/docs/developer-docs/smart-contracts/advanced-features/periodic-tasks.mdx index a3e2bc2579..669567cac0 100644 --- a/docs/developer-docs/smart-contracts/advanced-features/periodic-tasks.mdx +++ b/docs/developer-docs/smart-contracts/advanced-features/periodic-tasks.mdx @@ -59,7 +59,7 @@ For the code composability reasons, i.e. to be able to use different libraries w -```motoko +```motoko no-repl system func timer(setGlobalTimer : Nat64 -> ()) : async () { let next = Nat64.fromIntWrap(Time.now()) + 20_000_000_000; setGlobalTimer(next); // absolute time in nanoseconds @@ -200,7 +200,7 @@ To use multiple timers in a canister, simply create multiple timer definitions: In Motoko, call the `recurringTimer` function multiple times, setting different durations and callback functions for each timer: -```motoko +```motoko no-repl import { print } = "mo:base/Debug"; import { recurringTimer } = "mo:base/Timer"; diff --git a/docs/developer-docs/smart-contracts/advanced-features/time-and-timestamps.mdx b/docs/developer-docs/smart-contracts/advanced-features/time-and-timestamps.mdx index 65461ba9ba..e3a2d19857 100644 --- a/docs/developer-docs/smart-contracts/advanced-features/time-and-timestamps.mdx +++ b/docs/developer-docs/smart-contracts/advanced-features/time-and-timestamps.mdx @@ -28,7 +28,7 @@ Your canister can programmatically get system time to be used within your applic -```motoko +```motoko no-repl import { now } = "mo:base/Time"; import Debug "mo:base/Debug"; @@ -106,7 +106,7 @@ Below are examples showing how to convert Unix timestamps to DateTime format. -```motoko +```motoko no-repl import Time "mo:time/time"; import DateTime "mo:datetime/DateTime"; import Debug "mo:base/Debug"; @@ -155,7 +155,7 @@ fn to_date(timestamp: &u64) -> OffsetDateTime { For some applications, it may be useful to calculate the time that has passed between two timestamps. Below is an example canister written in Motoko that demonstrates how to use [timers](periodic-tasks.mdx) to generate two timestamps, then creates a function that can be used to calculate the difference: -```motoko +```motoko no-repl import Debug "mo:base/Debug"; import { setTimer; recurringTimer } = "mo:base/Timer"; import Time "mo:time/time"; diff --git a/docs/developer-docs/smart-contracts/call/arguments.mdx b/docs/developer-docs/smart-contracts/call/arguments.mdx index 21a9a317d4..5d61cf96c4 100644 --- a/docs/developer-docs/smart-contracts/call/arguments.mdx +++ b/docs/developer-docs/smart-contracts/call/arguments.mdx @@ -33,14 +33,13 @@ Motoko differentiates between immutable arrays, which cannot be altered, and mut import Nat "mo:base/Nat"; actor { - let numbers1 : [Nat] = [1, 2, 3, 4, 5, 6, 7]; // Immutable array - let numbers2 : [var Nat] = [var 1, 2, 3, 4, 5, 6, 7] ; // Mutable array + let _numbers1 : [Nat] = [1, 2, 3, 4, 5, 6, 7]; // Immutable array + let _numbers2 : [var Nat] = [var 1, 2, 3, 4, 5, 6, 7] ; // Mutable array - public func get_numbers(numbers2: [Nat]) : [Nat] { - return a; + public func get_numbers(numbers1: [Nat]) : async [Nat] { + return numbers1; } } - ``` The `Array` Motoko base library provides utility functions on arrays. To learn more about the `Array` Motoko base library, refer to the [Motoko base library reference on Array](/docs/current/motoko/main/base/Array) and the [Motoko language quick reference on arrays](/docs/current/motoko/main/reference/language-manual#arrays). diff --git a/docs/developer-docs/smart-contracts/candid/candid-concepts.mdx b/docs/developer-docs/smart-contracts/candid/candid-concepts.mdx index b0f74a7346..ecfd1944f0 100644 --- a/docs/developer-docs/smart-contracts/candid/candid-concepts.mdx +++ b/docs/developer-docs/smart-contracts/candid/candid-concepts.mdx @@ -285,7 +285,7 @@ In the [section above](#candid-service-descriptions), you learned how to write a For example, in Motoko, you can write a canister like this: -```motoko +```motoko no-repl actor { var v : Int = 0; public func add(d : Nat) : async () { v += d; }; diff --git a/docs/developer-docs/smart-contracts/candid/candid-howto.mdx b/docs/developer-docs/smart-contracts/candid/candid-howto.mdx index cfad511a46..2aa5fdf976 100644 --- a/docs/developer-docs/smart-contracts/candid/candid-howto.mdx +++ b/docs/developer-docs/smart-contracts/candid/candid-howto.mdx @@ -79,7 +79,7 @@ This workflow is for Motoko projects. You can import both interface descriptions into your canister with two import statements: -```motoko +```motoko no-repl import A "a.did";  // Imports only type definitions import service B "b.did";  // Imports both type definitions and main service ``` diff --git a/docs/developer-docs/smart-contracts/deploy/custom-testnets.mdx b/docs/developer-docs/smart-contracts/deploy/custom-testnets.mdx index 7aae737949..488944c165 100644 --- a/docs/developer-docs/smart-contracts/deploy/custom-testnets.mdx +++ b/docs/developer-docs/smart-contracts/deploy/custom-testnets.mdx @@ -56,7 +56,7 @@ Some settings you may want to change are: - Change the [Wasm transformation to fit your desired configuration](https://github.com/dfinity/motoko-playground/blob/main/service/pool/Main.mo#L150). In some cases, this may just be `wasm = args.wasm_module`, since if there is an `allowlist` in place, the principals allowed to install canisters can be trusted, such as: -```motoko +```motoko no-repl let wasm = args.wasm_module; ``` diff --git a/docs/developer-docs/smart-contracts/deploy/overview.mdx b/docs/developer-docs/smart-contracts/deploy/overview.mdx index f58a391bac..f97a19b93d 100644 --- a/docs/developer-docs/smart-contracts/deploy/overview.mdx +++ b/docs/developer-docs/smart-contracts/deploy/overview.mdx @@ -201,12 +201,13 @@ canister starts: import Time "mo:base/Time"; import Timer "mo:base/Timer"; import Nat64 "mo:base/Nat64"; +import Debug "mo:base/Debug"; actor { system func timer(setGlobalTimer : Nat64 -> ()) : async () { -   let next = Nat64.fromIntWrap(Time.now()) + 20_000_000_000; -   setGlobalTimer(next); // absolute time in nanoseconds -   print("Tick!"); + let next = Nat64.fromIntWrap(Time.now()) + 20_000_000_000; + setGlobalTimer(next); // absolute time in nanoseconds + Debug.print("Tick!"); } } ``` diff --git a/docs/developer-docs/smart-contracts/maintain/settings.mdx b/docs/developer-docs/smart-contracts/maintain/settings.mdx index cc8f078582..344901c429 100644 --- a/docs/developer-docs/smart-contracts/maintain/settings.mdx +++ b/docs/developer-docs/smart-contracts/maintain/settings.mdx @@ -197,7 +197,7 @@ An example of programmatically modifying canister settings: actor { let IC = actor "aaaaa-aa" : actor { - update_settings : { canister_id : Principal, } -> + update_settings : { canister_id : Principal } -> async (); }; }; diff --git a/docs/developer-docs/smart-contracts/maintain/storage.mdx b/docs/developer-docs/smart-contracts/maintain/storage.mdx index ea9c8896e9..e8c7793811 100644 --- a/docs/developer-docs/smart-contracts/maintain/storage.mdx +++ b/docs/developer-docs/smart-contracts/maintain/storage.mdx @@ -44,12 +44,11 @@ In Motoko canisters, stable memory can be utilized through the Motoko **stable s ```motoko actor Counter { -  stable var value = 0; - -  public func inc() : async Nat { -    value += 1; -    return value; -  }; + stable var value = 0; + public func inc() : async Nat { + value += 1; + return value; + }; } ``` diff --git a/docs/developer-docs/smart-contracts/signatures/signing-messages-t-ecdsa.mdx b/docs/developer-docs/smart-contracts/signatures/signing-messages-t-ecdsa.mdx index cbf324a3ad..019394b0b1 100644 --- a/docs/developer-docs/smart-contracts/signatures/signing-messages-t-ecdsa.mdx +++ b/docs/developer-docs/smart-contracts/signatures/signing-messages-t-ecdsa.mdx @@ -52,8 +52,7 @@ Currently only the `secp256k1` curve and the following key names are supported: -```motoko - +```motoko no-repl // Define the interface for the management canister. Only the `sign_with_ecdsa` method is used in this example: type IC = actor { sign_with_ecdsa : ({ @@ -146,8 +145,7 @@ The `chain_code` in the result can be used to derive child keys using a derivati -```motoko - +```motoko no-repl // Define the interface for the management canister. Only the `ecdsa_public_key` method is used in this example: type IC = actor { ecdsa_public_key : ({ diff --git a/docs/developer-docs/smart-contracts/signatures/signing-messages-t-schnorr.mdx b/docs/developer-docs/smart-contracts/signatures/signing-messages-t-schnorr.mdx index fa01493642..526d15ca08 100644 --- a/docs/developer-docs/smart-contracts/signatures/signing-messages-t-schnorr.mdx +++ b/docs/developer-docs/smart-contracts/signatures/signing-messages-t-schnorr.mdx @@ -47,7 +47,7 @@ To deploy code using the `sign_with_schnorr` method, you will need to specify th -```motoko +```motoko no-repl   public shared ({ caller }) func sign(message_arg : Text, algorithm_arg : SchnorrAlgotirhm) : async {     #Ok : { signature_hex : Text };     #Err : Text; @@ -254,7 +254,7 @@ To obtain public keys, you will need to call the `schnorr_public_key` method of -```motoko +```motoko no-repl   public shared ({ caller }) func public_key(algorithm_arg : SchnorrAlgotirhm) : async {     #Ok : { public_key_hex : Text };     #Err : Text; diff --git a/docs/developer-docs/smart-contracts/topping-up/cycles_management_services.mdx b/docs/developer-docs/smart-contracts/topping-up/cycles_management_services.mdx index d8a29b0b30..eb279625f5 100644 --- a/docs/developer-docs/smart-contracts/topping-up/cycles_management_services.mdx +++ b/docs/developer-docs/smart-contracts/topping-up/cycles_management_services.mdx @@ -40,7 +40,7 @@ You will still need to top up the CyclesManager canister manually. Here is example code for the 'CyclesManager' canister: -```motoko title="CyclesManager.mo" +```motoko no-repl title="CyclesManager.mo" // Import packages import { logand } "mo:base/Bool"; import { trap } "mo:base/Debug"; @@ -122,7 +122,7 @@ actor CyclesManager { Here is example code for the 'Child' canister: -```motoko Child.mo +```motoko no-repl Child.mo // Import the Mops package CyclesManager import CyclesRequester "mo:cycles-manager/CyclesRequester"; diff --git a/docs/developer-docs/smart-contracts/write/auto-scaling-architecture.mdx b/docs/developer-docs/smart-contracts/write/auto-scaling-architecture.mdx index 17a47b5bd6..72a39b51e0 100644 --- a/docs/developer-docs/smart-contracts/write/auto-scaling-architecture.mdx +++ b/docs/developer-docs/smart-contracts/write/auto-scaling-architecture.mdx @@ -35,7 +35,7 @@ The full code example can be found in the [sample's GitHub repo](https://github. First, this primary canister (stored in the `Main.mo` file) imports a variety of packages from the Motoko base library and data from the `IC.mo`, `Types.mo`, and `Datastore.mo` files: -```motoko +```motoko no-repl import Cycles "mo:base/ExperimentalCycles"; import Debug "mo:base/Debug"; import Iter "mo:base/Iter"; @@ -54,7 +54,7 @@ import Datastore "./Datastore"; Then, it creates a shared actor class containing type definitions: -```motoko +```motoko no-repl shared ({ caller }) actor class Self() {   type UserId = Types.UserId; @@ -69,39 +69,39 @@ shared ({ caller }) actor class Self() { Bind the caller principal to an _admin variable: -```motoko +```motoko no-repl   let _admin : Principal = caller; ``` Set a variable for the management canister: -```motoko +```motoko no-repl   // The IC management canister.   let IC : ICType.Self = actor "aaaaa-aa"; ``` Currently, a single canister smart contract is limited to 4 GiB of heap storage. In this project, you will ensure that the datastore canister does not meet this limit by restricting the memory usage to 2 GiB: -```motoko +```motoko no-repl   let DATASTORE_CANISTER_CAPACITY : Byte = 2_000_000_000; ``` This application will store notes. Each note will be limited to 1 MiB: -```motoko +```motoko no-repl   let NOTE_DATA_SIZE = 1_000_000; ``` The number of notes on a single datastore canister can be calculated as follows: -```motoko +```motoko no-repl   // DATASTORE_CANISTER_CAPACITY / NOTE_DATA_SIZE   let _numberOfDataPerCanister : Nat = DATASTORE_CANISTER_CAPACITY / NOTE_DATA_SIZE; ``` Configure stable variables for the application: -```motoko +```motoko no-repl   stable var _count = 0;   stable var _currentDatastoreCanisterId : ?DatastoreCanisterId = null;   stable var _stableUsers : [(UserId, User)] = []; @@ -116,7 +116,7 @@ Configure stable variables for the application: Define a series of functions for different purposes: -```motoko +```motoko no-repl   // Returns the current number of notes.   public query func count() : async Nat {     _count; @@ -202,7 +202,7 @@ Define a series of functions for different purposes: Define the logic to create a new note in the current datastore caller: -```motoko +```motoko no-repl   // Traps if:   //   - [caller] is not a registered user.   //   - there is no datastore canister. @@ -254,7 +254,7 @@ Define the logic to create a new note in the current datastore caller: Below is the logic that spawns a new canister from this master canister: -```motoko +```motoko no-repl   // Generates a new datastore canister.   // Returns a canister id of the generated canister.   // Traps if it fails to generate a new canister. @@ -291,7 +291,7 @@ Below is the logic that spawns a new canister from this master canister: Lastly, the code defines the upgrade logic for the canister: -```motoko +```motoko no-repl   // The work required before a canister upgrade begins.   system func preupgrade() {     Debug.print("Starting pre-upgrade hook..."); @@ -313,7 +313,7 @@ Lastly, the code defines the upgrade logic for the canister: Then, each secondary canister created by the primary canister will implement the following code (in this example, stored in the `Datastore.mo` file) : -```motoko +```motoko no-repl import Array "mo:base/Array"; import Buffer "mo:base/Buffer"; import Debug "mo:base/Debug"; diff --git a/docs/tutorials/developer-journey/level-1/1.2-motoko-lvl1.mdx b/docs/tutorials/developer-journey/level-1/1.2-motoko-lvl1.mdx index b517ecb376..2afcaa58f7 100644 --- a/docs/tutorials/developer-journey/level-1/1.2-motoko-lvl1.mdx +++ b/docs/tutorials/developer-journey/level-1/1.2-motoko-lvl1.mdx @@ -71,13 +71,13 @@ To import the base library, the `import` keyword can be used at the start of you For example, to import a local module named 'Debug', you can use the following import statement: -```motoko +```motoko no-repl import Debug "mo:base/Debug"; ``` Then, to use this imported library, you can call the module with a line of code such as: -```motoko +```motoko no-repl Debug.print("hello world"); ``` @@ -85,7 +85,7 @@ In this demonstration, you import Motoko code, indicated by the `mo:` prefix, th Additionally, you can import Motoko code and other modules using their relative paths. For example, if you have a Motoko program named `types.mo` that you'd like to import into your Motoko file, you can use the following import declaration: -```motoko +```motoko no-repl import Types "./types"; ``` diff --git a/docs/tutorials/developer-journey/level-1/1.3-first-dapp.mdx b/docs/tutorials/developer-journey/level-1/1.3-first-dapp.mdx index a6d706d7db..cd4c792a7d 100644 --- a/docs/tutorials/developer-journey/level-1/1.3-first-dapp.mdx +++ b/docs/tutorials/developer-journey/level-1/1.3-first-dapp.mdx @@ -131,7 +131,7 @@ Then, it declares the type of this variable as `Text`, which is the standard typ Since you are using the type `Text`, you need to import the type `Text` from the Motoko base library. To do this, add an import statement at the top of the file: -```motoko title="src/poll_backend/main.mo" +```motoko no-repl title="src/poll_backend/main.mo" import Text "mo:base/Text"; ``` @@ -169,7 +169,7 @@ Let's start with the first functionality; obtain the current poll question. To d The following example is a **code snippet** that is part of a larger code file. This snippet may return an error if run on its own. To view the full code file that should be run, please see [final code](#final-code). ::: -```motoko title="src/poll_backend/main.mo" +```motoko no-repl title="src/poll_backend/main.mo" public query func getQuestion() : async Text { question }; @@ -207,7 +207,6 @@ After adding the `getQuestion` method, your `main.mo` file should look like this ```motoko title="src/poll_backend/main.mo" import Text "mo:base/Text"; - actor { var question: Text = "What is your favorite programming language?"; @@ -244,7 +243,7 @@ In order to store and query the `RBTree` data structure, you need to import a fe To import these packages, add the following import statements to the beginning of the `main.mo` file: -```motoko title="src/poll_backend/main.mo" +```motoko no-repl title="src/poll_backend/main.mo" import RBTree "mo:base/RBTree"; import Nat "mo:base/Nat"; import Iter "mo:base/Iter"; @@ -253,7 +252,7 @@ import Iter "mo:base/Iter"; ### Declaring the `votes` variable Next, you need to add some code inside the actor to declare the variable for the data structure: -```motoko title="src/poll_backend/main.mo" +```motoko no-repl title="src/poll_backend/main.mo" var votes: RBTree.RBTree = RBTree.RBTree(Text.compare); ``` @@ -273,7 +272,7 @@ The following example is a **code snippet** that is part of a larger code file. ::: -```motoko title="src/poll_backend/main.mo" +```motoko no-repl title="src/poll_backend/main.mo" // query the list of entries and votes for each one // Example: // * JSON that the frontend will receive using the values above: @@ -309,7 +308,7 @@ The following example is a **code snippet** that is part of a larger code file. ::: -```motoko title="src/poll_backend/main.mo" +```motoko no-repl title="src/poll_backend/main.mo" // This method takes an entry to vote for, updates the data and returns the updated hashmap // Example input: vote("Motoko") // Example: @@ -354,7 +353,7 @@ Insert the following code into your `main.mo` file; there are inline comments th The following example is a **code snippet** that is part of a larger code file. This snippet may return an error if run on its own. To view the full code file that should be run, please see [final code](#final-code). ::: -```motoko title="src/poll_backend/main.mo" +```motoko no-repl title="src/poll_backend/main.mo" //This method resets the vote count for each option and returns the updated hashmap // Example JSON that the frontend will get using the values above // [["Motoko","0"],["Python","0"],["Rust","0"],["TypeScript","0"]] @@ -385,7 +384,6 @@ import Nat "mo:base/Nat"; import Text "mo:base/Text"; import Iter "mo:base/Iter"; - actor { var question: Text = "What is your favorite programming language?"; @@ -407,9 +405,7 @@ actor { }; - - - // This method takes an entry to vote for, updates the data and returns the updated hashmap +// This method takes an entry to vote for, updates the data and returns the updated hashmap // Example input: vote("Motoko") // Example: // * JSON that the frontend will receive using the values above: diff --git a/docs/tutorials/developer-journey/level-2/2.2-advanced-canister-calls.mdx b/docs/tutorials/developer-journey/level-2/2.2-advanced-canister-calls.mdx index daf05d20e8..e3d0457ceb 100644 --- a/docs/tutorials/developer-journey/level-2/2.2-advanced-canister-calls.mdx +++ b/docs/tutorials/developer-journey/level-2/2.2-advanced-canister-calls.mdx @@ -194,8 +194,7 @@ actor Publisher { Now, let's look at the corresponding 'Subscriber' canister. -```motoko title="src/sub/Main.mo" - +```motoko no-repl title="src/sub/Main.mo" // Import the Publisher canister import Publisher "canister:pub"; diff --git a/docs/tutorials/developer-journey/level-2/2.4-intro-candid.mdx b/docs/tutorials/developer-journey/level-2/2.4-intro-candid.mdx index c9c486dae8..43f8c91a70 100644 --- a/docs/tutorials/developer-journey/level-2/2.4-intro-candid.mdx +++ b/docs/tutorials/developer-journey/level-2/2.4-intro-candid.mdx @@ -260,7 +260,6 @@ cd candid_example You'll be using the sample Motoko canister that you looked at in the [generating service descriptions](#generating-service-descriptions) section earlier. Open the `src/candid_example_backend/main.mo` file in your code editor and replace the existing code with the following: ```motoko title="src/candid_example_backend/main.mo" - actor { var v : Int = 0; public func add(d : Nat) : async () { v += d; }; diff --git a/docs/tutorials/developer-journey/level-2/2.5-unit-testing.mdx b/docs/tutorials/developer-journey/level-2/2.5-unit-testing.mdx index 895b4c07b8..35cbacd4ed 100644 --- a/docs/tutorials/developer-journey/level-2/2.5-unit-testing.mdx +++ b/docs/tutorials/developer-journey/level-2/2.5-unit-testing.mdx @@ -32,7 +32,7 @@ Many of these tests use a library called Motoko Matchers. Motoko Matchers is a t Let's take a look at a simple unit test. This will test the program's error messages: -```motoko +```motoko no-repl import M "mo:matchers/Matchers"; import T "mo:matchers/Testable"; import Suite "mo:matchers/Suite"; @@ -65,7 +65,7 @@ This unit test does the following: ### Canister unit testing In addition to the `Suite`, `Testable` and `Matchers` packages, Motoko Matchers also contains a `Canister` package. The `Canister` package can be used to execute unit tests for canisters. Below is an example that uses this `Canister` package: -```motoko +```motoko no-repl import Canister "canister:CanisterName"; import C "mo:matchers/Canister"; import M "mo:matchers/Matchers"; diff --git a/docs/tutorials/developer-journey/level-2/2.6-motoko-lvl2.mdx b/docs/tutorials/developer-journey/level-2/2.6-motoko-lvl2.mdx index 647f21d771..7bbdc16260 100644 --- a/docs/tutorials/developer-journey/level-2/2.6-motoko-lvl2.mdx +++ b/docs/tutorials/developer-journey/level-2/2.6-motoko-lvl2.mdx @@ -49,7 +49,7 @@ This actor declares three public functions and one field: This actor `Counter` has the following type: -```motoko +```motoko no-repl actor { inc : shared () -> async (); read : shared () -> async Nat; @@ -61,7 +61,7 @@ In this definition, there are three 'members' of the actor which correlate to th In this type definition, you can see that each has the `shared` modifier for each member of the actor. Motoko allows you to omit this modifier when authoring an actor type, thus this can be simplified as: -```motoko +```motoko no-repl actor { inc : () -> async (); read : () -> async Nat; @@ -87,7 +87,7 @@ As you learned earlier, shared functions must be executed asynchronously and the To access the result of an async value, the receiver of the future use an `await` expression. For example, using the `Counter` actor you used previously, you can use the result of `Counter.read()` by binding the result value to an identifier (`a`), then await `a` to retrieve the `async Nat` return value, `n`: -```motoko +```motoko no-repl actor { let a : async Nat = Counter.read(); let n : Nat = await a; @@ -102,7 +102,7 @@ In this code, the following happens: These two lines can be combined into one to await an asynchronous call directly, such as: -```motoko +```motoko no-repl actor { let n : Nat = await Counter.read(); } @@ -160,7 +160,7 @@ Both the functions `get(k)` and `put(k, v)` use the `class` parameters of `n` an Then, you'll implement a coordinating `Map` actor in a file called `Map.mo`: -```motoko +```motoko no-repl import Array "mo:base/Array"; import Buckets "Buckets"; diff --git a/docs/tutorials/developer-journey/level-3/3.2-https-outcalls.mdx b/docs/tutorials/developer-journey/level-3/3.2-https-outcalls.mdx index 5824c1c33e..d827a78480 100644 --- a/docs/tutorials/developer-journey/level-3/3.2-https-outcalls.mdx +++ b/docs/tutorials/developer-journey/level-3/3.2-https-outcalls.mdx @@ -125,7 +125,7 @@ cd https_get Then, open the `src/https_get_backend/main.mo` file in your code editor and replace the existing content with: -```motoko title="src/https_get_backend/main.mo" +```motoko no-repl title="src/https_get_backend/main.mo" import Debug "mo:base/Debug"; import Blob "mo:base/Blob"; import Cycles "mo:base/ExperimentalCycles"; @@ -140,7 +140,7 @@ This piece of code imports the libraries that you'll be using. Each of these lib Next, insert the following line below these import statements: -```motoko title="src/https_get_backend/main.mo" +```motoko no-repl title="src/https_get_backend/main.mo" import Types "Types"; ``` @@ -148,7 +148,7 @@ This line imports the custom types stored in `Types.mo`. You'll create this file Following the `import Types "Types";` line, now let's insert the code to define our actor. This actor will contain two functions; a function to transform the response that you'll receive from our `GET` response, and a function that sends our `GET` request. The code has been annotated with notes describing in detail what each piece does: -```motoko title="src/https_get_backend/main.mo" +```motoko no-repl title="src/https_get_backend/main.mo" actor { // Create a function that transform's the raw content into an HTTP payload. @@ -289,7 +289,7 @@ This error occurs when the replicas on the subnet don't all return the same valu Once you've inserted these snippets of code into the `src/https_get_backend/main.mo` file, save the file. The file should look like this: -```motoko title="src/https_get_backend/main.mo" +```motoko no-repl title="src/https_get_backend/main.mo" import Debug "mo:base/Debug"; import Blob "mo:base/Blob"; import Cycles "mo:base/ExperimentalCycles"; @@ -498,7 +498,7 @@ cd https_post Then, open the `src/https_post_backend/main.mo` file in your code editor and replace the existing content with: -```motoko title="src/https_post_backend/main.mo" +```motoko no-repl title="src/https_post_backend/main.mo" import Debug "mo:base/Debug"; import Blob "mo:base/Blob"; import Cycles "mo:base/ExperimentalCycles"; @@ -511,7 +511,7 @@ import Types "Types"; This code is the same way you started your HTTP `GET` code. Now, you'll define an actor using that contain two functions; a function to transform the response that you'll receive from our `POST` response, and a function that sends our `POST` request. The code has been annotated with notes describing in detail what each piece does: -```motoko title="src/https_post_backend/main.mo" +```motoko no-repl title="src/https_post_backend/main.mo" actor { // This function is used to transform the response received from our POST request diff --git a/docs/tutorials/developer-journey/level-3/3.3-certified-data.mdx b/docs/tutorials/developer-journey/level-3/3.3-certified-data.mdx index 21e5a564c6..cebb2edfc3 100644 --- a/docs/tutorials/developer-journey/level-3/3.3-certified-data.mdx +++ b/docs/tutorials/developer-journey/level-3/3.3-certified-data.mdx @@ -89,7 +89,7 @@ Developers can certify their canister's data and assets in two ways: The Motoko base library includes a module called `CertifiedData` which contains the following system API methods for certified data: -```motoko +```motoko no-repl let set : (data : Blob) -> () let getCertificate : () -> ?Blob ``` @@ -207,7 +207,7 @@ mops install ic-certification@0.1.1 You can take a look at the source code for this canister in the `src/demo.mo` file to see how this code works. Let's take a look at a few snippets of it. For example, the function to submit the HTTP request uses the following code: -```motoko title="src/demo.mo" +```motoko no-repl title="src/demo.mo" public query func http_request(req : HttpRequest) : async HttpResponse { let cached = cache.get(req.url); @@ -249,7 +249,7 @@ In this function, if the HTTP `query` request returns a status code of `200`, th If the HTTP `query` request returns a status code of `404`, the request has failed and the request is upgraded to an `update` request. Then, the `http_request_update` function is called, which uses the following code: -```motoko title="src/demo.mo" +```motoko no-repl title="src/demo.mo" public func http_request_update(req : HttpRequest) : async HttpResponse { let url = req.url; diff --git a/docs/tutorials/developer-journey/level-3/3.6-motoko-lvl3.mdx b/docs/tutorials/developer-journey/level-3/3.6-motoko-lvl3.mdx index 4779b84f93..be2a46024b 100644 --- a/docs/tutorials/developer-journey/level-3/3.6-motoko-lvl3.mdx +++ b/docs/tutorials/developer-journey/level-3/3.6-motoko-lvl3.mdx @@ -164,7 +164,7 @@ import List "mo:base/List"; Then, declare your shared actor class which defines three role-based greetings to display using an if/else statement: -```motoko title="src/access_hello_backend/main.mo" +```motoko no-repl title="src/access_hello_backend/main.mo" shared({ caller = initializer }) actor class() { public shared({ caller }) func greet(name : Text) : async Text { @@ -180,7 +180,7 @@ shared({ caller = initializer }) actor class() { Next, define the custom types `Role` and `Permission`: -```motoko title="src/access_hello_backend/main.mo" +```motoko no-repl title="src/access_hello_backend/main.mo" public type Role = { #owner; #admin; @@ -195,14 +195,14 @@ Next, define the custom types `Role` and `Permission`: Then, define stable variables to store a list of principals and their associated role: -```motoko title="src/access_hello_backend/main.mo" +```motoko no-repl title="src/access_hello_backend/main.mo" private stable var roles: AssocList.AssocList = List.nil(); private stable var role_requests: AssocList.AssocList = List.nil(); ``` Create a function that checks if principal `a` equals principal `b`: -```motoko title="src/access_hello_backend/main.mo" +```motoko no-repl title="src/access_hello_backend/main.mo" func principal_eq(a: Principal, b: Principal): Bool { return a == b; }; @@ -210,7 +210,7 @@ Create a function that checks if principal `a` equals principal `b`: Define a function to get the principal's current role, first by checking if the principal is the initializer of the canister, then by checking the list that stores principals and their associated role: -```motoko title="src/access_hello_backend/main.mo" +```motoko no-repl title="src/access_hello_backend/main.mo" func get_role(pal: Principal) : ?Role { if (pal == initializer) { ?#owner; @@ -223,7 +223,7 @@ Define a function to get the principal's current role, first by checking if the Then, determine if a principal has a role with permissions: -```motoko title="src/access_hello_backend/main.mo" +```motoko no-repl title="src/access_hello_backend/main.mo" func has_permission(pal: Principal, perm : Permission) : Bool { let role = get_role(pal); switch (role, perm) { @@ -236,7 +236,7 @@ Then, determine if a principal has a role with permissions: Define a function that rejects any unauthorized principals: -```motoko title="src/access_hello_backend/main.mo" +```motoko no-repl title="src/access_hello_backend/main.mo" func require_permission(pal: Principal, perm: Permission) : async () { if ( has_permission(pal, perm) == false ) { throw Error.reject( "unauthorized" ); @@ -246,7 +246,7 @@ Define a function that rejects any unauthorized principals: Define a function to assign a new role to a principal: -```motoko title="src/access_hello_backend/main.mo" +```motoko no-repl title="src/access_hello_backend/main.mo" public shared({ caller }) func assign_role( assignee: Principal, new_role: ?Role ) : async () { await require_permission( caller, #assign_role ); @@ -271,7 +271,7 @@ Define a function to assign a new role to a principal: Return the principal of the message caller/user identity: -```motoko title="src/access_hello_backend/main.mo" +```motoko no-repl title="src/access_hello_backend/main.mo" public shared({ caller }) func callerPrincipal() : async Principal { return caller; }; @@ -280,7 +280,7 @@ Return the principal of the message caller/user identity: Return the role of the message caller/user identity: -```motoko title="src/access_hello_backend/main.mo" +```motoko no-repl title="src/access_hello_backend/main.mo" public shared({ caller }) func my_role() : async ?Role { return get_role(caller); }; @@ -536,7 +536,7 @@ For example, consider the following function call: import Text "mo:base/Text"; actor { - let name : Text = fullName({ first = "Jane"; mid = "M"; last = "Doe" }); + let name = ({ first = "Jane"; mid = "M"; last = "Doe" }); }; ``` @@ -580,7 +580,7 @@ Since heartbeats are a legacy feature, new canisters should opt to use timers in To support timers, the Motoko `Timer.mo` library exists. The following is a simple example that creates a periodic reminder for logging a message every new year: -```motoko +```motoko no-repl import { print } = "mo:base/Debug"; import { abs } = "mo:base/Int"; import { now } = "mo:base/Time"; @@ -606,7 +606,7 @@ In this code, there is a global timer that issues callbacks from a queue maintai The following is an example of a global timer expiration callback that gets called immediately after the canister starts, such as immediately after install, then periodically every twenty seconds thereafter: -```motoko +```motoko no-repl actor { system func timer(setGlobalTimer : Nat64 -> ()) : async () { let next = Nat64.fromIntWrap(Time.now()) + 20_000_000_000; diff --git a/docs/tutorials/developer-journey/level-4/4.6-motoko-lvl4.mdx b/docs/tutorials/developer-journey/level-4/4.6-motoko-lvl4.mdx index 83a1782504..e954011c2f 100644 --- a/docs/tutorials/developer-journey/level-4/4.6-motoko-lvl4.mdx +++ b/docs/tutorials/developer-journey/level-4/4.6-motoko-lvl4.mdx @@ -46,7 +46,7 @@ actor { Mutable variables use the `var` syntax when being declared, such as: -```motoko +```motoko no-repl import Text "mo:base/Text"; import Nat "mo:base/Nat"; @@ -58,7 +58,7 @@ actor { To update the values of the mutable variables, you can use the following syntax with the assignment operation `:=`, which works for all types: -```motoko +```motoko no-repl actor { textMutable := textMutable # "xyz"; pairMutable := (textMutable, pairMutable.1); @@ -124,7 +124,7 @@ Before going deeper into mutable arrays, first let's cover immutable arrays, whi For example, consider the following immutable array: -```motoko +```motoko no-repl import Nat "mo:base/Nat"; actor { @@ -162,19 +162,19 @@ This array holds three numbers with type `Nat`. These three values can be update To declare a mutable array with a dynamic size, such that the number of entries within the array can be updated, the following `Array_init` syntax can be used: -```motoko +```motoko no-repl import Nat "mo:base/Nat"; import Array "mo:base/Array"; actor { - ar size : Nat = 52 ; + ar size : Nat; let x : [var Nat] = Array.init(size, 5); } ``` Using this syntax, this mutable array will have `size` number of entries, each with an initial value of `5`. Then, to update this mutable array, you can use the syntax: -```motoko +```motoko no-repl x[2] := 42; ``` @@ -236,7 +236,7 @@ By default, all declarations in an object block are private, such as the variabl In the previous object declaration, `counter` has the following object type, which is expressed using a list of `field` type pairs: -```motoko +```motoko no-repl { inc : () -> () ; read : () -> Nat ; @@ -287,7 +287,7 @@ actor { The object type for the object `bumpCounter` exposes only one operation, `bump`: -```motoko +```motoko no-repl { bump : () -> Nat ; } @@ -295,7 +295,7 @@ The object type for the object `bumpCounter` exposes only one operation, `bump`: This example exposes the most common operation and only permits a certain behavior. In another part of a program, you may want to implement another version with more generality, such as our example from earlier: -```motoko +```motoko no-repl { inc : () -> () ; read : () -> Nat ; @@ -305,7 +305,7 @@ This example exposes the most common operation and only permits a certain behavi Lastly, you may implement a type with additional operations, such as a `write` operation: -```motoko +```motoko no-repl { inc : () -> () ; read : () -> Nat ; @@ -320,7 +320,7 @@ If a function expects to receive an object using the first type `({ bump: () → Now let's move onto object classes. An object class is a package of entities that share a common name. For example, let's define a class example for counters that start at zero: -```motoko +```motoko no-repl import Nat "mo:base/Nat"; actor { @@ -336,7 +336,7 @@ actor { Using this definition, you can construct new counters each with their own unique state that start at zero, such as: -```motoko +```motoko no-repl actor { let c1 = Counter(); let c2 = Counter(); @@ -345,13 +345,12 @@ actor { Then, you can use each counter, `c1` and `c2`, independently of one another: -```motoko +```motoko no-repl actor{ let x = c1.inc(); let y = c2.inc(); (x, y) } - ``` In comparison, the same results can be achieved by using a constructor function to return an object: @@ -409,7 +408,7 @@ The inspect system function should not be used as a definitive form of access co Consider the following `inspect` function example that denies all ingress messages and ignores all message information: -```motoko +```motoko no-repl system func inspect({}) : Bool { false } ``` @@ -457,7 +456,7 @@ Motoko error handling best practices recommend to use `Option` and `Result` erro If a function wants to return the value of type `A`, or signal an error can return a value of option type `?A`, the `null` value can designate the error. For example, consider the following `markDone` function that returns an async value of `?Seconds`. -```motoko +```motoko no-repl import Time "mo:base/Time"; actor { @@ -477,7 +476,7 @@ actor { Then, you can use the following error callsite: -```motoko +```motoko no-repl import Int "mo:base/Int"; import Text "mo:base/Text"; @@ -501,13 +500,13 @@ One drawback of this method is that all possible errors return a single, non-inf As an alternative to using `Option` types, `Result` variants can be used to return richer, more defined errors that provide better descriptions of what went wrong. `Result` variants are a built-in type that is defined as such: -```Motoko +```motoko no-repl type Result = { #ok : Ok; #err : Err } ``` Since `Result` includes the `Err` type parameters, the `Result` type allows you to select the type used to describe errors. Consider the following example that uses `Result` variants to signal errors: -```Motoko +```motoko no-repl import Result "mo:base/Result"; import Time "mo:base/Time"; @@ -532,7 +531,7 @@ actor { Then, you can use the following error callsite: -```motoko +```motoko no-repl import Time "mo:base/Time"; import Text "mo:base/Text"; import Int "mo:base/Int"; @@ -565,7 +564,7 @@ Asynchronous errors is a restricted form of exception error handling. Since Moto Asynchronous error handling generally should only be used for catching and signally unexpected, irrecoverable failures. If a failure can be handled by the caller, it should return a `Result` instead. The following example demonstrates a form of asynchronous error handling: -```motoko +```motoko no-repl import Time "mo:base/Time"; actor { @@ -589,7 +588,7 @@ actor { Then, you can use the following error callsite: -```motoko +```motoko no-repl import Text "mo:base/Text"; actor { diff --git a/docs/tutorials/developer-journey/level-5/5.1-vetKeys-tutorial.mdx b/docs/tutorials/developer-journey/level-5/5.1-vetKeys-tutorial.mdx index 512e8d2124..074d206a05 100644 --- a/docs/tutorials/developer-journey/level-5/5.1-vetKeys-tutorial.mdx +++ b/docs/tutorials/developer-journey/level-5/5.1-vetKeys-tutorial.mdx @@ -242,7 +242,7 @@ Next, review the `src/encryptedNotes_motoko/main.mo` file, which contains the co It is important to note that this backend canister does *not* perform any encryption, since it assumes that the notes are encrypted end-to-end by the front-end (at the client side). ::: -```motoko title="src/encryptedNotes_motoko/main.mo" +```motoko no-repl title="src/encryptedNotes_motoko/main.mo" // First, import the necessary libraries: import Map "mo:base/HashMap"; diff --git a/docs/tutorials/developer-journey/level-5/5.2-ICP-ETH-tutorial.mdx b/docs/tutorials/developer-journey/level-5/5.2-ICP-ETH-tutorial.mdx index ff020d6790..3c869780ea 100644 --- a/docs/tutorials/developer-journey/level-5/5.2-ICP-ETH-tutorial.mdx +++ b/docs/tutorials/developer-journey/level-5/5.2-ICP-ETH-tutorial.mdx @@ -104,7 +104,7 @@ In this file, you can see the definitions for the project's four canisters: Next, let's take a look at the source code for the backend canister. Open the `backend/Backend.mo` file, which will contain the following content. This code has been annotated with notes to explain the code's logic: -```motoko title="backend/Backend.mo" +```motoko no-repl title="backend/Backend.mo" import EvmRpc "canister:evm_rpc"; diff --git a/docs/tutorials/developer-journey/level-5/5.3-token-swap-tutorial.mdx b/docs/tutorials/developer-journey/level-5/5.3-token-swap-tutorial.mdx index 3fd7154bf0..a2f9807381 100644 --- a/docs/tutorials/developer-journey/level-5/5.3-token-swap-tutorial.mdx +++ b/docs/tutorials/developer-journey/level-5/5.3-token-swap-tutorial.mdx @@ -115,7 +115,7 @@ In this project's configuration, you can see definition of three canisters: Next, open the `src/swap/main.mo` file and review its contents. This code has been annotated with notes to explain the program's functionality: -```motoko title="src/swap/main.mo" +```motoko no-repl title="src/swap/main.mo" import Blob "mo:base/Blob"; import Debug "mo:base/Debug"; import Iter "mo:base/Iter"; @@ -359,7 +359,7 @@ shared (init_msg) actor class Swap( Next, open the `ICRC.mo` file and review its contents. This file defines several types that are imported in the `main.mo` file: -```motoko title="src/swap/ICRC.mo" +```motoko no-repl title="src/swap/ICRC.mo" module ICRC { public type BlockIndex = Nat; public type Subaccount = Blob; diff --git a/docs/tutorials/developer-journey/level-5/5.4-NFT-tutorial.mdx b/docs/tutorials/developer-journey/level-5/5.4-NFT-tutorial.mdx index 0300866b18..f54edcd8d4 100644 --- a/docs/tutorials/developer-journey/level-5/5.4-NFT-tutorial.mdx +++ b/docs/tutorials/developer-journey/level-5/5.4-NFT-tutorial.mdx @@ -120,7 +120,7 @@ ADMIN_PRINCIPAL=$(dfx identity get-principal) To configure the settings of your NFT collection, replace the existing content in `example/initial_state/icrc7.mo` with your own configuration, such as: -```motoko title="example/initial_state/icrc7.mo" +```motoko no-repl title="example/initial_state/icrc7.mo" import ICRC7 "mo:icrc7-mo"; module{ diff --git a/docs/tutorials/developer-journey/level-5/5.5-auction-tutorial.mdx b/docs/tutorials/developer-journey/level-5/5.5-auction-tutorial.mdx index 159d708ea3..8de92f3fbc 100644 --- a/docs/tutorials/developer-journey/level-5/5.5-auction-tutorial.mdx +++ b/docs/tutorials/developer-journey/level-5/5.5-auction-tutorial.mdx @@ -153,7 +153,7 @@ This project contains three canisters, as seen in the `dfx.json` file: Next, open the `src/backend/AuctionServer.mo` file. This file will contain a template that includes placeholder functions; to provide full functionality in your dapp, you will need to replace the template code with functioning code. To do that, start by removing the existing code in the `src/backend/AuctionServer.mo` file and insert the following code that has been annotated to explain the code's logic: -```motoko title="src/backend/AuctionServer.mo" +```motoko no-repl title="src/backend/AuctionServer.mo" /// Import the necessary libraries: import Principal "mo:base/Principal"; diff --git a/docs/tutorials/hackathon-prep-course/3-exploring-the-backend.mdx b/docs/tutorials/hackathon-prep-course/3-exploring-the-backend.mdx index 7883a9d4ac..107652f967 100644 --- a/docs/tutorials/hackathon-prep-course/3-exploring-the-backend.mdx +++ b/docs/tutorials/hackathon-prep-course/3-exploring-the-backend.mdx @@ -77,19 +77,19 @@ Let's breakdown each portion of this code. First, the code defines an actor called `Backend`. In Motoko, programs consist of an actor expression that is introduced using the keyword `actor`. An actor is a process with encapsulated state that communicates with other running actors. Each canister can only contain one actor. You can learn more about Motoko actors [here](/docs/current/tutorials/developer-journey/level-1/1.2-motoko-lvl1). -```motoko title="backend/Backend.mo" +```motoko no-repl title="backend/Backend.mo" actor class Backend() { ``` Next, the code defines a variable (`var`) called `counter` with a value of `0`. This variable is defined with the word `stable`, which indicates it is a **stable variable**. A stable variable is a variable defined within an actor which uses the `stable` keyword in the variable's declaration. This indicates that the data stored in the variable should be persisted during canister upgrades. This tutorial will go further into stable storage in the section [stable memory](#stable-memory) If this stable keyword is not used, the variable is defined as flexible by default. -```motoko title="backend/Backend.mo" +```motoko no-repl title="backend/Backend.mo" stable var counter = 0; ``` Next, the code defines a public function called `get()`. The function is modified with the keyword `query`, which defines calls to this function will use a query call. A query call is used for querying information from a canister's method. This tutorial will go into further detail on query calls in the section [query and update calls](#query-and-update-calls). This function simply returns the value of the `counter` variable. -```motoko title="backend/Backend.mo" +```motoko no-repl title="backend/Backend.mo" public query func get() : async Nat { counter; }; @@ -97,7 +97,7 @@ public query func get() : async Nat { In the next portion of the code, a public function called `inc()` is defined. This function increases the value of the `counter` variable by `1` every time the function is called. -```motoko title="backend/Backend.mo" +```motoko no-repl title="backend/Backend.mo" public func inc() : async () { counter += 1; }; @@ -105,7 +105,7 @@ public func inc() : async () { Lastly, the `add(n : Nat)` function is defined. This function adds `n` to the current count, where `n` is a numerical value passed to the function when it is called. In the frontend UI, the button used to increase the counter value does not use this function, however it can be called manually from the command line or Candid interface of the backend canister. This tutorial will go into further detail on Candid in the section [Candid](#candid). -```motoko title="backend/Backend.mo" +```motoko no-repl title="backend/Backend.mo" public func add(n : Nat) : async () { counter += n; };