A simple example demonstrating cross-contract calls in CosmWasm smart contracts

Overview

Cross-contract calls

This tutorial demonstrates cross-contract calls with CosmWasm v1.

Overview

An end user calls the reservation contract to register for an upcoming dinner. The user will have to pay a little to get on the list, unless they've been given a scholarship and added to a special list. The special list is its own contract, and the list of registrants also lives in another contract.

This is a trivial example to demonstrate cross-contract calls.

Contracts

There are three contracts here:

  1. Reservation โ€” this contract doesn't do much besides perform cross-contract calls to dinner contracts. It also stores how many times this contract has successfully registered people for dinner. ๐Ÿฝ๏ธ
  2. Scholarship list โ€” using the whitelist contract from cw-plus, we keep a list of addresses that can register for dinner without paying. The compiled contract lives in the directory whitelist-binary.
  3. Dinners โ€” the dinner contract keeps track of dinner attendees. For demonstration purposes, each instance keeps track of only one dinner. For production, you may not want to implement it this way.

Scenarios

Assuming there haven't been mistakes in deploying and initializing the three contracts, here are the success and failure scenarios.

Success

A normal person calls the reservation contract attaching funds to pay for their attendance.

A person whose address exists on the scholarship contract calls the reservation contract, without attaching funds.

Failure

A normal person calls the reservation contract but doesn't attach enough funds.

A person calls the reservation contract, but provides an invalid dinner contract address.

A registered person attempts to register again.

The dinner registration window has closed and a person tries to register.

Starting csli

/Users/mike/Documents/csli/bin/cosmjs-cli.mjs --init cosmjs-cli-helpers/cosmwasm-init.ts --code cosmjs-cli-helpers/cosmwasm-code.ts
You might also like...
CosmWasm multi-contract testing framework

Multi Test: Test helpers for multi-contract interactions Warning: Alpha Software Designed for internal use only. This is used for testing cw-plus cont

Template for multi-contract CosmWasm projects

CosmWasm Template Template for multi-contract CosmWasm projects How to Use Install cargo-make: cargo install --force cargo-make Run formatter: cargo m

Examples and helpers to build NFT contracts on CosmWasm

CosmWasm NFTS This repo is the official repository to work on all NFT standard and examples in the CosmWasm ecosystem. cw721 and cw721-base were moved

Demonstrating how to use Rust to interact with the Solana blockchain.

Solana Scripts This is a library of Rust scripts for specific purposes: Generate a new wallet Create an SPL token Mint an SPL token Get an associated

Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) โ›๐Ÿ‘ท๐Ÿšงโš ๏ธ
Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) โ›๐Ÿ‘ท๐Ÿšงโš ๏ธ

Solana BPF Boilerplate Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana This boilerplate provides the following. Si

A Simple Rust NFT API + Smart Contract

Rust NFT API Purpose Rust NFT API is a simple RESTful API developed in Rust that offers functionalities for creating, retrieving, and listing Non-Fung

evm2near compiles Solidity contracts into NEAR WebAssembly contracts.

EVM โ†’ NEAR evm2near is a project for compiling EVM bytecode into wasm bytecode, with the particular goal of having that wasm artifact be executable on

Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin.
Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin.

dlctix Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin. This project is part of the Backdrop Build

Substrate NFT !ink smart contract base

Substrate !ink NFT simple implementation This is a simple working version of base NFT smart contract written using latest (as of this date) !ink 3.0.0

Comments
  • Create contracts with cross-contract call

    Create contracts with cross-contract call

    Closes #1 Changed dinner and demo-totals so that they work and demo-totals makes a cross-contract call to dinner. Created tests and scripts build.sh and deploy.sh for building and deploying to uni-3 testnet.

    Also dinner doesn't actually make cross-contract call to cw1_whitelist through submessages, it only queries the state:

    deps.querier.query_wasm_smart(
        SCHOLARSHIPS_ADDRESS.load(deps.storage)?,
        &cw1_whitelist::msg::QueryMsg::AdminList::<String> {},
    )?;
    

    Is it okay for this example?

    opened by NinoLipartiia 2
  • Get cross-contract calls working!

    Get cross-contract calls working!

    Nothing works, I'm pretty sure. But we can start out by reading the README and undestanding what's supposed to happen.

    Also, this should help, I drew it myself: PXL_20220822_072501530 MP_2

    Then, immerse yourself in love, and in this entire page. Memorize it: https://docs.cosmwasm.com/docs/1.0/smart-contracts/contract-semantics/#submessages

    opened by mikedotexe 0
  • Fix README

    Fix README

    Look at the picture here #1 and notice that some things have changed from the README. like I think it used to be called "reservation" but it's now "demo totals"

    Go around clean stuff up. Also, the last section in the README is about the CSLI REPL, which isn't what we're about anymore. That's old hat. We're now onto: https://github.com/csli-tools/cli

    So let's figure out how to remove/replace that last part, too.

    opened by mikedotexe 0
Owner
csli Tools
๐Ÿ—ฃ "sizzly" is a set of DevX tools for Cosmos blockchains
csli Tools
An example CosmWasm contract for connecting contracts over IBC.

CosmWasm IBC Example This is a simple IBC enabled CosmWasm smart contract. It expects to be deployed on two chains and, when prompted, will send messa

ekez 64 Jun 21, 2023
Cosmwasm in Cosmwasm through ComposableFi/cosmwasm-vm

Cosmwasmception Running Fastest way to run this contract would be through our vm. But note that our vm runs an already built version this contract, so

Abdullah Eryuzlu 3 Oct 5, 2022
CosmWasm/Sylvia counting contract w/ IBC enabled (Cosmos, Rust, CosmWasm, Sylvia)

CosmWasm/Sylvia counting contract w/ IBC enabled (Cosmos, Rust, CosmWasm, Sylvia) This repository contains counting contract created during the study

Alex Cryp 3 Nov 13, 2023
My code for the terra.academy course on CosmWasm smart contracts

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

Alex Incerti 0 Nov 7, 2021
A gRPC-based scripting library for interacting with CosmWasm smart-contracts.

Cosmos Rust Script Smart contract scripting library to ease CosmWasm smart contract development and deployment. cosm-script is inspired by terra-rust-

null 11 Nov 3, 2022
A blazingly fast compiling & optimization tool for CosmWasm smart contracts.

cw-optimizoor A blazingly fast alternative to CosmWasm/rust-optimizer for compiling & optimizing CW smart contracts. It's primarily meant to speed up

Sebastian Mandrean 37 Apr 15, 2023
Minimal Substrate node configured for smart contracts via pallet-contracts.

substrate-contracts-node This repository contains Substrate's node-template configured to include Substrate's pallet-contracts โ€’ a smart contract modu

Parity Technologies 73 Dec 30, 2022
Minimal flashloan borrower contracts with an extensible rust sdk to abstract wrapping generic onchain calls (similar to multicall3) with flashloans.

flashloan-rs โ€ข Minimal flashloan borrower contracts with an extensible rust sdk. Getting Started Flashloan-rs is published to crates.io as flashloan-r

White Noise 71 Apr 15, 2023
An example smart contract that builds on top of xyz

xyz Guestbook Tutorial Contract This repository contains an example smart contract that illustrates how to build on top of the xyz NFT contract. This

null 5 Apr 4, 2022
Example NFT marketplace project using ink! smart contract.

NFT Marketplace project This contract is an example for the NFT marketplace implementation. License Apache 2.0 ??๏ธ How to use - Contracts ?? Build Use

Swanky dApps 8 Jan 18, 2023