XION
DiscordGithub
  • Welcome to XION
  • XION'S Core
    • Concepts
      • Generalized Chain Abstraction
      • Intro to Account Abstraction
      • XION's Meta Accounts
      • Meta Accounts Design
      • Architecture & Tech Glossary
      • Use Cases
  • developers
    • XION Quick Start
      • Zero to App in 5 Minutes
        • Launch a User Map App on XION in 5 Minutes
        • React Native Mobile App on XION in 5 Minutes
        • Todo App
          • Build a TODO App using the Collection-Document Storage Smart Contract
          • Build a TODO Mobile App using the DocuStore Contract
    • Mobile App Development
      • Set up your XION Mobile Development Environment
      • Build a TODO Mobile App using the DocuStore Contract
      • Create Mobile App and Integrate Meta Account Authentication
      • Building a React Native Mobile App with Abstraxion (Xion.js)
    • Getting Started (Advanced)
      • Set Up Local Environment
        • Setting up your Local Smart Contract Development Environment for XION
          • Setting up your XION Smart Contract Development Environment on Windows (WSL2 + Ubuntu)
        • Set Up an Integrated Development Environment (IDE)
        • Interacting with Xion Chain using Xion Daemon
      • Your First Contract
        • Deploying Your First Smart Contract on XION
      • Gasless UX & Permission Grants
        • Enabling Gasless Transactions with Treasury Contracts
      • App Development
        • Account Abstraction with Gasless Transactions
        • Interact with XION via your Backend Service
    • Re-using Existing Contracts
      • Deployed Contracts on XION
      • Non-Fungible Tokens (NFTs)
      • Fungible Tokens
      • Marketplace
      • Multisig
      • Proxy Contracts
      • Membership Management
      • Governance
      • Valuts
      • SCV Audited Contracts
    • Web3 for Web2 Developers
      • Web2 vs Web3 App Architecture: A Comparison
      • Misconceptions and Misapplied Web2 Patterns
      • Recommended Architecture for Apps on XION
    • Building for Mainnet
      • Xion Testnet: Your Development Playground
      • Building with Audited & Battle-Tested Contracts
      • Community Engagement: Building Support for Your app
      • Deploying to Xion Mainnet
        • Smart Contract Audits: Process, Costs & Support
        • Governance Process to Deploying Smart Contracts to Mainnet
    • Learn & Build
      • Token Factory
        • Creating, Minting, and Interacting with a Token Factory Token
        • Building a React dApp to Interact with Token Factory Tokens
        • Integrating a Token Factory Token in a Smart Contract
      • Websockets
        • WebSockets with Xion: Real-Time Communication
      • Oracles
        • Creating a Smart Contract with Pyth Oracle Integration
      • Indexers: Optimized Data Retrieval
        • SubQuery
      • Use Cases
        • Building a Per-User Data Storage App
        • Build a TODO App using the Collection-Document Storage Smart Contract
      • Crossmint Integration
        • Crossmint Digital Collectibles Checkout via Credit Card
    • Reference and Resources
      • Requesting XION Testnet Tokens
      • Public Endpoints & Resources
      • Block Explorers
      • Governance
        • Deploying Smart Contracts to Mainnet
      • Developer Tools: Abstract
      • IBC Denoms on XION Networks
      • Frequently Asked Questions
      • XION Token Contract Addresses on EVM Chains
  • Nodes & Validators
    • Run a Node
      • System Specifications
      • Build the Xion Daemon
      • Download the Xion Daemon
      • Configure the Xion Daemon
        • app.toml
        • client.toml
        • config.toml
      • Join the XION Network
        • xion-testnet-1
      • Confirm node is running
    • Become a Validator
      • Initial Setup
      • Obtain a XION Wallet Address
      • Obtain Funds
        • Testnet
      • Create Validator
    • IBC Relayers and Tokens
  • Others
    • Resources
Powered by GitBook
On this page
  • Return Types in Entry Point Functions
  • Usage of Response Type
  • Query Entry Point Exception
  • Basic Usage of Response

Was this helpful?

Edit on GitHub
  1. developers
  2. Reference and Resources
  3. CosmWasm Resources
  4. Contract Semantics

Events

Last updated 1 year ago

Was this helpful?

Return Types in Entry Point Functions

The typical return type for entry point functions is Result<Response, ContractError, where Response acts as a container for Events in the Cosmos SDK.

Usage of Response Type

In the context of a contract's entry point, like instantiate or execute, Response should be returned as the successful outcome. It can be declared as mutable and modified within the function's body. However, a more prevalent approach is to construct it at the end and return it if all computations have been successful. In the forthcoming examples, Response is wrapped by Ok since it is returned as part of a function yielding the Result type, with Response signifying the Right or success branch.

Query Entry Point Exception

The Query entry point is an exception to this pattern, as it returns StdResult in accordance with the Cosmos SDK interface.

For a deeper understanding of the Response struct, you can explore the source code .

Basic Usage of Response

The most straightforward use of Response involves:

Ok(Response::default ())

This is a common occurrence in instantiate functions when there is no message to be returned to the client. Nevertheless, in the majority of cases when dealing with the execute function, it is expected that a Response should be returned, like so.

let res = Response::new()
.add_attribute("action", "transfer")
.add_attribute("from", info.sender)
.add_attribute("to", recipient)
.add_attribute("amount", amount);
Ok(res)

In-Depth Analysis of the Code Snippet

This code snippet involves several additional steps, so let's delve deeper into its workings.

Steps in the Code

  1. A new Response is generated.

  2. Several key/value pairs are added to this Response.

  3. The Response is returned, encapsulated within a Result type using Ok.

Command-Line Interface Observations

When you invoke your contract through the command-line interface (CLI), you'll notice these steps logged as part of the "raw_log" response, alongside other SDK events.

Utilizing add_event

Instead of solely appending attributes, the add_event function can be utilized to include an unencapsulated event that can be interacted with by other clients or contracts.

To explore the source code for this example, you can access it by clicking

here
here.