Cronos EVM Docs
  • Getting Started
    • Getting Started
    • Background
    • Architecture
    • Cronos roadmap
  • FOR USERS
    • 💳Crypto.com Card Top Up
    • 🔥Crypto Wallets
    • 🦊MetaMask Configuration
    • 🦁Brave Wallet
    • 🌉Bridges
      • From the Crypto.com App and Exchange
        • From the Crypto.com App
        • From the Crypto.com Exchange
      • IBC (Cronos POS Chain, other Cosmos chains)
        • Cronos Bridge Web App
      • Independent bridges
      • FAQs for Bridge transfers
      • FAQs for transactions from/to centralized exchanges
    • 🚰Testnet Faucet
    • 💡Tips & FAQs
    • 👮Key Principles for Wallet Security
    • GasTracker
  • FOR DAPP DEVELOPERS
    • 💡Founder FAQs
    • 🏅Hacker's Getting Started Resources
    • 📃Smart Contracts
      • Contract Development on Testnet
      • Contract Deployment and Verification
      • Contract Verification Export: Cronoscan To Cronos Explorer
      • Best Practices
      • Token Contract Addresses
    • 💻dApp Creation
      • Free and commercial RPC endpoints
      • Wallet integrations
      • Web3-wallet
      • JSON-RPC methods
      • Address Conversion
      • Swagger Playground
    • ⚙️Dev Tools & Integrations
      • All dev tools & integrations
      • Account Abstraction (Experimental)
      • Band Protocol
      • Banxa
      • GoldRush
      • Cronos Safe
      • Flair
      • Google Bigquery
      • Moralis
      • Pyth
      • Secret Network
      • SubQuery
      • Witnet
    • Crypto.com AI Agent SDK
  • FOR NODE HOSTS
    • Running nodes
      • Cronos Mainnet
        • Quicksync
        • State-sync
        • Public Node Sync
        • KSYNC
        • The "Huygen" upgrade guide (v0.6.* to v0.7.*)
        • The "v0.7.0-hotfix" upgrade guide (v0.7.* to v0.8.*)
        • The "Galileo" upgrade guide (v0.8.* to v1.0.*)
        • The "Titan" upgrade guide (v1.0.* to v1.1.0)
        • The "v1.2" upgrade guide (v1.1.* to v1.2.0)
        • The "v1.3" upgrade guide (v1.2.* to v1.3.0)
        • The "v1.4" Pallene upgrade guide (v1.3.* to v1.4.1)
        • Patching Unlucky & Duplicate Tx
      • Cronos Testnet
      • Devnet
      • Best Practices
      • Cronosd build with Nix
      • VersionDB
      • MemIAVL
      • Local State Sync
    • Cronosd
  • CRONOS PLAY
    • Introduction
    • Unity Engine
      • Current Version
      • Legacy Version
        • EVM
        • Login Example
        • Custom RPC
        • ERC20
        • ERC721
        • ERC1155
      • Useful Links
    • Unreal Engine
      • Installation and Enabling
      • Working with Blueprint
        • Actors and Blueprint Classes
        • Cronos Configuration
        • Connect Defi Desktop/Onchain Wallet with URI
        • Connect Wallets with QR Code
        • Connect WalletConnect Step by Step
        • WalletConnect 2.0 and Unreal Engine 5: Hello World Example
        • Wallet
        • ERC20
        • ERC721
        • ERC1155
        • Broadcast Transactions
        • Get Tokens or Transactions
      • Working with C++
        • Creating a C++ Project
        • Creating a child DefiWalletCoreActor
        • Querying a contract
        • Customizing Network
      • Demo
    • Cronos Play C++ SDK
    • Crypto.com Pay Integration
    • Cronos Play FAQ
  • Block Explorers
    • Block Explorer and API Keys
    • Cronos Explorer
    • Cronoscan
  • CRONOS CHAIN PROTOCOL
    • Chain ID and Address Format
    • Cronos General FAQ
    • Genesis
    • Modules
      • module_bank
      • module_distribution
      • module_slashing
      • module_feemarket
    • Chain Details
      • List of parameters
      • Technical glossary
      • Protocol Documentation
    • Common IBC Commands
  • Cronos zkEVM
    • Cronos zkEVM
  • Resources
    • Media / brand kit
Powered by GitBook
On this page
  • Overview
  • Pre-requisites
  • Integration guide for Cronos
  • Create a new project
  • Download the latest ChainSafe SDK and import it into the project.
  • Prefabs interaction
  • Build and Run
  • What's next
  • Reference
  • Import Sample package from Unity Asset Store
  • Smart contract
  • NFT Faucet
  • (Optional) List NFT for sale in marketplace faucet

Was this helpful?

Edit on GitHub
  1. CRONOS PLAY
  2. Unity Engine
  3. Legacy Version

2D Game Example

Last updated 5 months ago

Was this helpful?

Overview

This section showcases the Cronos play Gaming SDK integration with the Cronos chain, aiming to bring Unity games into the Cronos ecosystem. In particular, we will show how to do a basic integration of the Cronos play with the Cronos chain including:

  • Connecting to Cronos networks;

  • Installaiton of the SDK;

  • Obtaining a sample NFT and;

  • Import Sample package from Unity Asset Store

Pre-requisites

  1. (Version 2020.3.25f1 or later)

Network Name: Cronos Mainnet Beta

  • New RPC URL: https://evm-dev.cronos.org/

  • Chain ID: 25

  • Currency Symbol: CRO

  • Block Explorer URL: https://explorer.cronos.org/

Network Name: Cronos Testnet

  • New RPC URL: https://evm-dev-t3.cronos.org/

  • Chain ID: 338

  • Currency Symbol: TCRO

  • Block Explorer URL: https://explorer.cronos.org/testnet

  • Sufficient funds on deployer address

  • For Crypto.com Onchain Wallet integration, please refer to our .

Integration guide for Cronos

Create a new project

Download the latest ChainSafe SDK and import it into the project.

Prefabs interaction

  • Step 3a. [Unity] Double click the Level1 scene under Assets/Scenes directory

Transfer721 Example

  • Drag the Transfer721 prefab under Assets/Web3Unity/Prefabs/WebGL dir into the scene.

  • Update the Contract address under Transfer721Script object inspector

  • Update the To Account address to your desired wallet address



Build and Run

  1. Switch to WebGL platform

  1. Click the Player Setting button

  2. Select Web3GL-2020 under Resolution and Presentation tab

  1. Set Compression Format to Disabled under Publishing Settings tab

  1. After that, click Build and Run button and you are ready to play.

What's next

Reference

Import Sample package from Unity Asset Store

1a. Click to add the asset and sign in to your Unity account

1b. Create a new project in Unity

1c. Open the Package Manager window in Unity and under "My Assets" download the Bolt Kit.

1d. Select Bolt Kit: Platformer Tutorial Assets and click Import


Smart contract

2a. Create an ERC standard smart contract

  • ERC20 example

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts@4.4.2/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts@4.4.2/access/Ownable.sol";

contract MyToken is ERC20, Ownable {
    constructor() ERC20("MyToken", "MTK") {
        _mint(msg.sender, 1000 * 10 ** decimals());
    }

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}
  • ERC721 example

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts@4.4.2/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.4.2/access/Ownable.sol";
import "@openzeppelin/contracts@4.4.2/utils/Counters.sol";

contract MyNFT is ERC721, Ownable {
    using Counters for Counters.Counter;

    Counters.Counter private _tokenIdCounter;

    constructor() ERC721("MyNFT", "MNFT") {}

    function _baseURI() internal pure override returns (string memory) {
        return "https://opensea-creatures-api.herokuapp.com/api/creature/";
    }

    function safeMint(address to) external onlyOwner {
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
    }
}
  • ERC1155 example

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts@4.4.2/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts@4.4.2/access/Ownable.sol";

contract My1155Token is ERC1155, Ownable {
    constructor()
        ERC1155("https://opensea-creatures-api.herokuapp.com/api/creature/")
    {}

    function setURI(string memory newuri) public onlyOwner {
        _setURI(newuri);
    }

    function mint(address account, uint256 id, uint256 amount, bytes memory data)
        public
        onlyOwner
    {
        _mint(account, id, amount, data);
    }

    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        public
        onlyOwner
    {
        _mintBatch(to, ids, amounts, data);
    }
}
-  Switch the chain network to Cronos Testnet via Metamask extension or other similar provider
-  Select the `Injected Web3` under ENVIRONMENT tab
-  Approve the connection
-  Select your contract name under CONTRACT tab
-  Approve the transaction after clicking `Deploy` button
-  Copy the contract address

NFT Faucet

  • 1. Connect your wallet via metamask or walletconnect

  • 2. Click Create NFT under YOUR COLLECTION tab

  • 3. Create and sign the transaction after uploading the image

  • 4. Copy the contract address and image URL from the NFT modal

  • 5. Paste into the corresponding input box inside Unity inspector


(Optional) List NFT for sale in marketplace faucet

  • 1. Fill in the price at list item modal and confirm

  • 2. Sign approval and create item transaction

  • 3. View the listed item in Marketplace tab

Download the tutorial bolt kit from and import the assets into the blank new project. Below are the steps for importing Tutorial Projects - Bolt Kit from Unity. See .

For a detailed explanation, please refer to

* For acquiring the NFT, you can create your own (see ), or mint an ERC721 NFT at our (see ).

The above guideline documentation only highlights the basic integration between ChainSafe and Cronos chain. You can download the full source code of the above sample game . For other ERC protocol methods, please refer to the .

2b. Deploy Smart Contract via

Unity
ChainSafe SDK
Metamask browser extension
Testnet Faucet
documentation
ChainSafe official documentation
here
ChainSafe Documentation
Remix IDE
Unity
Reference #1
Cronos NFT faucet
Reference #2
Reference #3