diff --git a/docs/developers/best-practices/the-dynamic-allocation-problem.md b/docs/developers/best-practices/the-dynamic-allocation-problem.md index 15f97959..45aa3efc 100644 --- a/docs/developers/best-practices/the-dynamic-allocation-problem.md +++ b/docs/developers/best-practices/the-dynamic-allocation-problem.md @@ -65,5 +65,5 @@ Make sure you migrate to the managed types **incrementally** and **thoroughly te ::: :::tip -You can use the `mxpy contract report` command to verify whether your contract still requires dynamic allocation or not. +You can use the `sc-meta report` command to verify whether your contract still requires dynamic allocation or not. ::: diff --git a/docs/developers/meta/sc-build-reference.md b/docs/developers/meta/sc-build-reference.md index 337a3c3d..543d2775 100644 --- a/docs/developers/meta/sc-build-reference.md +++ b/docs/developers/meta/sc-build-reference.md @@ -7,18 +7,12 @@ title: Build Reference ## How to: Basic build -To build a contract, it is enough to navigate in your contract crate and run +To build a contract, navigate to the contract folder and run the following command: ```sh sc-meta all build ``` -:::info Note -The traditional way to trigger a build in console is to call `mxpy contract build --path `, which works as well. However, mxpy currently just forwards commands to the [MultiversX Metaprogramming standalone tool](/developers/meta/sc-meta#introduction), so you might as well call it directly. -::: - ---- - [comment]: # (mx-exclude-context) ## Configuring the build @@ -155,11 +149,11 @@ After building the contracts, there are three more operations left to perform, b ### g. Cleaning a project -Calling `cargo run clean` in the meta crate will run `cargo clean` in all wasm crates and delete the `output` folder. +In order to clean a project and remove all build artifacts, run the following command: -`mxpy contract clean` also just forwards to this. - -Note that even the clean operation relies on the ABI, in order to reach all the wasm crates. +```sh +sc-meta all clean +``` [comment]: # (mx-context-auto) diff --git a/docs/developers/meta/sc-meta-cli.md b/docs/developers/meta/sc-meta-cli.md index 0c4765e7..3fc79929 100644 --- a/docs/developers/meta/sc-meta-cli.md +++ b/docs/developers/meta/sc-meta-cli.md @@ -388,7 +388,7 @@ This command is similar to `build-dbg`, in that it provides a shorthand for buil ### Calling `clean` -Calling `mxpy contract clean ` or `cargo run clean` in the meta crate will delete the `output` folder and clean outputs of the Rust crates. +Calling `sc-meta all clean` in the contract folder will remove all build artifacts, including the `output` folder. [comment]: # (mx-context-auto) @@ -419,4 +419,4 @@ Calling `cargo run cs` in the meta crate or `sc-meta cs` in the root crate will Subcommands: - `install` Pulls the latest chain simulator docker image available. This command needs Docker to be installed and running on the current machine. - `start` Starts the chain simulator in verbose mode at `localhost:8085`. -- `stop` Stops the chain simulator. \ No newline at end of file +- `stop` Stops the chain simulator. diff --git a/docs/developers/overview.md b/docs/developers/overview.md index 60c25392..28c7d62e 100644 --- a/docs/developers/overview.md +++ b/docs/developers/overview.md @@ -40,7 +40,6 @@ Below is a list of tutorials for building on MultiversX: | [Build a microservice for your dApp](/developers/tutorials/your-first-microservice) | Video + written tutorial on how to create your microservice. | | [Crowdfunding Smart Contract](/developers/tutorials/crowdfunding-p1) | Crowdfunding tutorial (Part 1). | | [Crowdfunding Smart Contract](/developers/tutorials/crowdfunding-p2) | Crowdfunding tutorial (Part 2). | -| [The Counter Smart Contract](/developers/tutorials/counter) | The Counter SC tutorial. | | [Staking contract Tutorial](/developers/tutorials/staking-contract) | Step by step tutorial on how to create a Staking Smart Contract. | | [Energy DAO Tutorial](/developers/tutorials/energy-dao) | In depth analysis of the Energy DAO SC template. | | [DEX Walkthrough](/developers/tutorials/dex-walkthrough) | In depth walkthrough of all the main DEX contracts. | diff --git a/docs/developers/tutorials/counter.md b/docs/developers/tutorials/counter.md deleted file mode 100644 index e96efe76..00000000 --- a/docs/developers/tutorials/counter.md +++ /dev/null @@ -1,134 +0,0 @@ ---- -id: counter -title: The Counter Smart Contract ---- -[comment]: # (mx-abstract) -By following the tutorial on this page, you will learn how to build, deploy and interact with a basic Smart Contract (written in C). - -:::important -This is a mere example. We **do not offer support for writing contracts in C**. The recommended language to write smart contracts is **Rust**. -::: - -[comment]: # (mx-context-auto) - -## **Prerequisites** - -You need to have `mxpy` installed. Follow the installation guide [here](/sdk-and-tools/sdk-py/installing-mxpy). - -[comment]: # (mx-context-auto) - -## **Create the contract** - -In a folder of your choice, add the files contained at [this](https://github.com/multiversx/mx-deprecated-sc-examples-clang/tree/master/simple-counter) location. - -The file `counter.c` is the implementation of the Smart Contract, which defines the following functions: - -- `init()`: this function is executed when the contract is deployed on the Blockchain -- `increment()` and `decrement()`: these functions modify the internal state of the Smart Contract -- `get()`: this is a pure function (does not modify the state) which we'll use to query the value of the counter - -[comment]: # (mx-context-auto) - -## **Build the contract** - -In order to build the contract to WASM, run the following command: - -``` -mxpy --verbose contract build --path mycounter -``` - -Above, `mycounter` refers to the folder that holds the source code. After executing the command, you can inspect the generated files in `mycounter/output`. - -[comment]: # (mx-context-auto) - -## **Deploy the contract on the Testnet** - -In order to deploy the contract on the Testnet you need to have an account with sufficient balance (required for the deployment fee) and the associated private key in **PEM format**. - -The deployment command is as follows: - -``` -mxpy --verbose contract deploy --bytecode=./mycounter/output/counter.wasm --pem="alice.pem" --gas-limit=5000000 --proxy="https://testnet-gateway.multiversx.com" --outfile="counter.json" --recall-nonce --send -``` - -Above, `mycounter` refers to the same folder that contains the source code and the build artifacts. The `deploy` command knows to search for the WASM bytecode within this folder. - -Note the last parameter of the command - this instructs mxpy to dump the output of the operation in the specified file. The output contains the address of the newly deployed contract and the hash of the deployment transaction. - -``` -counter.json -{ - "emittedTransaction": { - "nonce": 773, - "value": "0", - "receiver": "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu", - "sender": "erd1...", - "gasPrice": 1000000000, - "gasLimit": 5000000, - "data": "MDA2MTczNmQwMTAwMDA...MDA=", - "chainID": "T", - "version": 2, - "signature": "bfee..." - }, - "emittedTransactionData": "0061...", - "contractAddress": "erd1qqqqqqqqqqqqq..." -} - -``` - -Feel free to inspect these values in the [Explorer](https://explorer.multiversx.com/). - -[comment]: # (mx-context-auto) - -## **Interact with the deployed contract** - -Let's extract the contract address from `counter.json` before proceeding to an actual contract execution. - -``` -export CONTRACT_ADDRESS=$(python3 -c "import json; data = json.load(open('counter.json')); print(data['contractAddress'])") -``` - -Now that we have the contract address saved in a shell variable, we can call the `increment` function of the contract as follows: - -``` -mxpy --verbose contract call $CONTRACT_ADDRESS --pem="alice.pem" --gas-limit=2000000 --function="increment" --proxy="https://testnet-gateway.multiversx.com" --recall-nonce --send -``` - -Execute the command above a few times, with some pause in between. Then feel free to experiment with calling the `decrement` function. - -Then, in order to query the value of the counter - that is, to execute the `get` pure function of the contract - run the following: - -``` -mxpy contract query $CONTRACT_ADDRESS --function="get" --proxy="https://testnet-gateway.multiversx.com" -``` - -The output should look like this: - -``` -[{'base64': 'AQ==', 'hex': '01', 'number': 1}] -``` - -[comment]: # (mx-context-auto) - -## **Interaction script** - -The previous steps can be summed up in a simple script as follows: - -``` -#!/bin/bash - -# Deployment -mxpy --verbose contract deploy --bytecode=./mycounter/output/counter.wasm --pem="alice.pem" --gas-limit=5000000 --proxy="https://testnet-gateway.multiversx.com" --outfile="counter.json" --recall-nonce --send -export CONTRACT_ADDRESS=$(python3 -c "import json; data = json.load(open('address.json')); print(data['contractAddress'])") - -# Interaction -mxpy --verbose contract call $CONTRACT_ADDRESS --pem="alice.pem" --gas-limit=2000000 --function="increment" --proxy="https://testnet-gateway.multiversx.com" --recall-nonce --send -sleep 10 -mxpy --verbose contract call $CONTRACT_ADDRESS --pem="alice.pem" --gas-limit=2000000 --function="increment" --proxy="https://testnet-gateway.multiversx.com" --recall-nonce --send -sleep 10 -mxpy --verbose contract call $CONTRACT_ADDRESS --pem="alice.pem" --gas-limit=2000000 --function="decrement" --proxy="https://testnet-gateway.multiversx.com" --recall-nonce --send -sleep 10 - -# Querying -mxpy contract query $CONTRACT_ADDRESS --function="get" --proxy="https://testnet-gateway.multiversx.com" -``` diff --git a/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v12.md b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v12.md index 6771f5e1..b0b83a86 100644 --- a/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v12.md +++ b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v12.md @@ -315,7 +315,7 @@ const tx4 = factory.createMultiESDTNFTTransfer({ import { Code } from "@multiversx/sdk-core"; import { promises } from "fs"; -let buffer = await promises.readFile("../contracts/counter.wasm"); +let buffer = await promises.readFile("../contracts/adder.wasm"); let code = Code.fromBuffer(buffer); ``` @@ -326,7 +326,7 @@ let code = Code.fromBuffer(buffer); ```js import axios from "axios"; -let response = await axios.get("https://github.com/multiversx/mx-sdk-js-core/raw/main/src/testdata/counter.wasm", { +let response = await axios.get("https://github.com/multiversx/mx-sdk-js-core/raw/main/src/testdata/adder.wasm", { responseType: "arraybuffer", transformResponse: [], headers: { @@ -421,7 +421,7 @@ console.log("Return code:", returnCode); import { AbiRegistry, Address, SmartContract } from "@multiversx/sdk-core"; import { promises } from "fs"; -let abiJson = await promises.readFile("../contracts/counter.abi.json", { encoding: "utf8" }); +let abiJson = await promises.readFile("../contracts/adder.abi.json", { encoding: "utf8" }); let abiObj = JSON.parse(abiJson); let abiRegistry = AbiRegistry.create(abiObj); let existingContractAddress = Address.fromBech32("erd1qqqqqqqqqqqqqpgq5sup58y38q3pwyqklagxmuraetshrqwpd8ssh0ssph"); @@ -435,7 +435,7 @@ let existingContract = new SmartContract({ address: existingContractAddress, abi ```js import axios from "axios"; -const response = await axios.get("https://github.com/multiversx/mx-sdk-js-core/raw/main/src/testdata/counter.abi.json"); +const response = await axios.get("https://github.com/multiversx/mx-sdk-js-core/raw/main/src/testdata/adder.abi.json"); abiRegistry = AbiRegistry.create(response.data); existingContract = new SmartContract({ address: existingContractAddress, abi: abiRegistry }); ``` @@ -742,13 +742,13 @@ console.log(untypedBundle.returnCode, untypedBundle.values.length); ```js let endpointDefinition = AbiRegistry.create({ - "name": "counter", + "name": "adder", "endpoints": [{ - "name": "increment", - "inputs": [], - "outputs": [{ "type": "i64" }] + "name": "add", + "inputs": [{ "type": "u64" }], + "outputs": [{ "type": "u64" }] }] -}).getEndpoint("increment"); +}).getEndpoint("add"); transactionOnNetwork = await networkProvider.getTransaction(txHash); let typedBundle = resultsParser.parseOutcome(transactionOnNetwork, endpointDefinition); diff --git a/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md index 462b4209..41e96b1e 100644 --- a/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md +++ b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md @@ -376,7 +376,7 @@ let abi = AbiRegistry.create(abiObj); ```js import axios from "axios"; -const response = await axios.get("https://github.com/multiversx/mx-sdk-js-core/raw/main/src/testdata/counter.abi.json"); +const response = await axios.get("https://github.com/multiversx/mx-sdk-js-core/raw/main/src/testdata/adder.abi.json"); abi = AbiRegistry.create(response.data); ``` diff --git a/docs/sdk-and-tools/sdk-py/mxpy-cli.md b/docs/sdk-and-tools/sdk-py/mxpy-cli.md index 8d8fdea0..1302abe5 100644 --- a/docs/sdk-and-tools/sdk-py/mxpy-cli.md +++ b/docs/sdk-and-tools/sdk-py/mxpy-cli.md @@ -608,7 +608,7 @@ Now let's deploy a smart contract using the Ledger: ```sh mxpy contract deploy --proxy=https://devnet-gateway.multiversx.com --recall-nonce \ - --bytecode=counter.wasm --gas-limit=5000000 \ + --bytecode=adder.wasm --gas-limit=5000000 \ --ledger --ledger-address-index=42 \ --send ``` @@ -618,7 +618,7 @@ Then, perform a contract call: ```sh mxpy contract call erd1qqqqqqqqqqqqqpgqwwef37kmegph97egvvrxh3nccx7xuygez8ns682zz0 \ --proxy=https://devnet-gateway.multiversx.com --recall-nonce \ - --function increment --gas-limit 5000000 \ + --function add --arguments 42 --gas-limit 5000000 \ --ledger --ledger-address-index=42 \ --send ``` diff --git a/sidebars.js b/sidebars.js index ec9c327d..00d73895 100644 --- a/sidebars.js +++ b/sidebars.js @@ -54,7 +54,6 @@ const sidebars = { "developers/tutorials/your-first-microservice", "developers/tutorials/crowdfunding-p1", "developers/tutorials/crowdfunding-p2", - "developers/tutorials/counter", "developers/tutorials/staking-contract", "developers/tutorials/energy-dao", "developers/tutorials/dex-walkthrough",