This Solidity smart contract is designed to create a marketplace for buying and selling ERC721 tokens. The contract uses the OpenZeppelin library for security and reentrancy protection.
The contract has the following main components:
makeItem
: Allows users to list their ERC721 tokens for sale.purchaseItem
: Allows users to buy listed ERC721 tokens.getTotalPrice
: Calculates the total price including the fee.
This contract depends on the following OpenZeppelin libraries:
@openzeppelin/contracts/token/ERC721/IERC721.sol
: Interface for ERC721 tokens.@openzeppelin/contracts/security/ReentrancyGuard.sol
: Reentrancy guard to prevent reentrancy attacks.
To set up this contract on a local environment, follow these steps:
-
Install Solidity compiler: Download and install the latest version of the Solidity compiler from the official website (https://solidity.readthedocs.io/en/latest/installing-solidity.html).
-
Install Hardhat: Hardhat is a development environment for Ethereum. Install it using npm:
npm install -g hardhat
- Deploy smart contracts locally
npx hardhat run ./src/backend/scripts/deploy.js --network localhost
- Run the environment
npx hardhat node