Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Decentraland Scene — Access Rights to a Virtual Environment

This is the final project for the Blockchain & Smart Contracts exam at the University of Cagliari (UniCa).

The Decentraland scene features a public area open to anyone and a reserved area separated by a door. Access to the reserved area requires a valid NFT ticket (unused and not expired), issued by an ERC-721 smart contract on the Sepolia testnet. Walking through the door consumes the ticket with the nearest expiration.

License: GPL-3.0-or-later (see LICENSE).


Prerequisites

  • Node.js 18+ and npm.
  • MetaMask (browser extension), with a connected account.
  • Sepolia test ETH in the account (from a Sepolia faucet).
  • Decentraland SDK7: installed locally with npm install inside scene/ (see the guide below).

Part 1 — Smart contract (Hardhat + Sepolia)

  1. From the root folder:
cd contract
npm install
cp .env.example .env
  1. In the .env file, set:
  • SEPOLIA_RPC_URL — Sepolia RPC endpoint
  • PRIVATE_KEY — private key of an account holding Sepolia ETH
  • (optional) TICKET_PRICE_ETH, TICKET_VALIDITY_SECONDS
  1. Compile and run the tests (in-memory local network):
npm run compile
npm test
  1. Deploy to Sepolia:
npm run deploy:sepolia

The script prints the contract address and saves the address + ABI to contract/deployments/sepolia.json. Note down the address.

  1. (Optional) Estimate gas and execution costs (Ethereum vs Polygon):
npx hardhat run scripts/gas-costs.js

The script measures gas live on the in-memory local network and computes the costs for the various scenarios. The reference prices (gas price and token value) can be edited at the top of scripts/gas-costs.js.


Part 2 — Decentraland scene

  1. Connect the contract and the scene. In scene/src/contract/config.ts, paste the deployment address:

    export const CONTRACT_ADDRESS = "<copied_address>"

    If the contract interface was changed, also update scene/src/contract/abi.ts (copy the abi array from contract/deployments/sepolia.json).

  2. Install and start the preview:

    cd scene
    npm install
    npm start

    The start script runs sdk-commands start --dclenv zone --web3:

    • --dclenv zone selects the test environment (Sepolia) instead of production;
    • --web3 connects the browser wallet to sign transactions.

    Required condition:

    • MetaMask set to the Sepolia network before interacting.

    The scene still performs a check (assertSepolia) and blocks any transaction if the wallet is not on Sepolia, so it never spends real ETH. To deliberately start in the production environment: npm run start:mainnet.

  3. Usage flow in the scene:

    • Go to the statue (in the public area) and click → MetaMask asks you to sign the ticket purchase.
    • Approach the door and click "Enter" → If you hold a valid ticket, MetaMask asks you to sign useTicket(); on success, the door opens and you can access the reserved area.

License

Project distributed under the GNU General Public License v3.0 or later. Every source file carries the SPDX header GPL-3.0-or-later. The OpenZeppelin dependencies are MIT (compatible with the GPL). See LICENSE for the full text.

About

This is the final project for the Blockchain & Smart Contracts exam at the University of Cagliari (UniCa).

Resources

Stars

Watchers

Forks

Contributors

Languages