ltfschoen / XCMTemplate

Building Cross-chain (XCM) DApps with Docker
Mozilla Public License 2.0
3 stars 0 forks source link
astar blockchain cargo-contract docker ethereum evm ink ink-python moonbeam polkadot polkadot-js python rust smart-contracts solidity substrate substrate-contracts-node truffle wasm webassembly

Smart Contracts using XCM

Table of Contents

Setup

Setup Docker Container

Run Cargo Contracts Node in Docker Container

Run Node

./docker/run-scn.sh

Interact with Node

Demo Quickstart Build & Upload ink! Rust Flipper Smart Contract to Local Testnet (using Cargo Contract)

Option 1: Run from host machine

SCN_PORT=$(docker exec -it ink lsof -ti:30333) && \
docker exec -it ink echo $(kill -9 $SCN_PORT) && \
docker exec -it ink /app/docker/reset.sh && \
docker exec -it ink /app/docker/quickstart.sh

Option 2: Run from shell inside Docker container

* Enter shell of Docker container
    ```bash
    docker exec -it ink /bin/bash
    ```
* Run quickstart
    ```bash
    ./docker/reset.sh
    ./docker/quickstart.sh
    ```

Demo Quickstart Build & Upload ink! Rust "Basic Contract Caller" Smart Contract to Local Testnet (using Cargo Contract)

Run from shell inside Docker container

* Enter shell of Docker container
    ```bash
    docker exec -it ink /bin/bash
    ```
* Run in terminal tab 1
    ```bash
    ./docker/reset.sh
    ```
* Run in terminal tab 2
    ```
    ./docker/quickstart-basic-contract-caller.sh
    ```

Demo Quickstart Build & Upload ink! Rust "IPSP22" Smart Contract to Local Testnet (using Cargo Contract)

Run from shell inside Docker container

* Enter shell of Docker container
    ```bash
    docker exec -it ink /bin/bash
    ```
* Run in terminal tab 1
    ```bash
    ./docker/reset.sh
    ```
* Run in terminal tab 2
    ```bash
    cd /app
    ./docker/quickstart-ipsp22.sh
    ```

Demo Quickstart Build & Upload ink! Rust "Unnamed" Smart Contract to Local Testnet (using Cargo Contract)

Run from shell inside Docker container

* First run a Cargo Contracts Node, by following the steps in the section "Run Cargo Contracts Node in Docker Container"

* Enter shell of Docker container
    ```bash
    docker exec -it ink /bin/bash
    ```
* Run in terminal tab 1
    ```bash
    ./docker/reset.sh
    ```
* Run in terminal tab 2
    ````
    ./docker/quickstart-unnamed.sh
    ```

Build & Upload Moonbeam VRF Randomness Precompile Solidity Smart Contract to Moonbase Alpha Testnet (using Truffle)

./docker/quickstart-moonbeam-vrf-precompile.sh

Build & Upload Chainlink VRFD20 Randomness Solidity Smart Contract to Ethereum Sepolia Testnet (using Truffle)

Build & Upload ink! Rust Flipper Smart Contract to Local Testnet (using Cargo Contract)

UNSUPPORTED Build & Upload ink! Rust Flipper Smart Contract to Local Testnet (using Swanky CLI)

WARNING: Swanky CLI is not supported by this repository using Docker until this issue is resolved https://github.com/inkdevhub/swanky-cli/issues/222#issuecomment-2062847896 WARNING: Swanky CLI only supports older versions of ink!, cargo-contract, and rustc, so you might need to downgrade to the following versions to get it to work, as mentioned here https://github.com/inkdevhub/swanky-cli/issues/222#issuecomment-2062847896

  • ink v4.2.1 or v5 to ink 4.0.0
  • cargo-contract v4.1.0 to v2.1.0
  • rustc 1.77.2 (25ef9e3d8 2024-04-09) to rustc to 1.69 (2023-03-21)

The versions that are used in the Docker container are specified in ./docker/Dockerfile.

Install Swanky CLI https://github.com/AstarNetwork/swanky-cli

cd dapps/ink-rust
nvm install
nvm use
yarn global add @astar-network/swanky-cli@3.1.0

Show Swanky help https://docs.astar.network/docs/build/wasm/swanky-suite/cli/

swanky help --nested-commands

Create New Flipper template

Add Flipper smart contract template (only if that folder does not exist yet) to generate https://github.com/AstarNetwork/wasm-flipper.

swanky init flipper

Note: Choose ink as a contract language and flipper as template and a chosen contract name. Optionally choose from Y/N when asking to download the Swanky Node (NOT required if already using Substrate Contracts Node).

If you chose to download the Swanky Node then run it in your local environment:

cd ./flipper
yarn
yarn run run-node

Note: The command yarn run run-node runs swanky node start

Use Existing wasm-flipper Example

Warning: It is old and outdated and may not work

  1. Init
cd ./wasm-flipper
cd contract
  1. Start the local node

If you chose to download the Swanky Node then run it in your local environment:

cd flipper
swanky node start

Compile Contract

  1. Build the contract

Build the contract in a new tab

swanky contract compile flipper

Note: Try rustup update if you face error

  1. Deploy the contract

Local Testnet

swanky contract deploy flipper --account alice -g 1000000000000 -a true

Shibuya Testnet

swanky contract deploy flipper --account alice --gas 1000000000000 --args true --network shibuya

Copy paste the contract address.

  1. Update WS_PROVIDER to check if it connects to Shibuya or localhost in ./dapps/ink-rust/wasm-flipper/ui/components/app.tsx

  2. View in block explorer if deploy on Astar https://astar.subscan.io/wasm_contract_dashboard?tab=contract Note: If you deployed on Shibuya then go to https://shibuya.subscan.io/

Interact with ink! Python Smart Contract

Obtain Shibuya from faucet at https://portal.astar.network/shibuya-testnet/assets

Interact with ink! Rust Flipper Smart Contract using Polkadot.js API

Interact with ink! Rust Flipper Smart Contract using Substrate Contracts Node

Cargo Contracts

...
Event System => NewAccount
    account: 5G...
...
Event Contracts + Instantiated
    deployer: 5F...
    contract: 5G.... (new contract account address to interact with contract)
...
cargo contract call \
    --suri //Charlie \
    --contract $CONTRACT_ADDR \
    --message flip \
    --execute \
    --skip-confirm
cargo contract call \
    --suri //Charlie \
    --contract $CONTRACT_ADDR \
    --message get \
    --execute \
    --skip-confirm

Tips Docker Commands

Notes

TODO - continue summarising from "Smart contract accounts" section

Links

Ink

Docker