From 481dd2ddb6c1cd3a52eb165aa2909faddbb0ff2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Sun, 24 Nov 2024 22:09:02 +0200 Subject: [PATCH] Remove page on old "counter" contract (not buildable anymore). --- docs/developers/overview.md | 1 - docs/developers/tutorials/counter.md | 134 ------------------ .../sdk-js/sdk-js-cookbook-v13.md | 2 +- docs/sdk-and-tools/sdk-py/mxpy-cli.md | 4 +- sidebars.js | 1 - 5 files changed, 3 insertions(+), 139 deletions(-) delete mode 100644 docs/developers/tutorials/counter.md diff --git a/docs/developers/overview.md b/docs/developers/overview.md index 60c25392a..28c7d62e3 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 e96efe76c..000000000 --- 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-v13.md b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md index 462b42092..41e96b1ef 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 8d8fdea01..1302abe56 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 ec9c327d1..00d738954 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",