---
# System prepended metadata

title: RIF Marketplace Example Setup

---

# RIF Marketplace Example Setup
 
Github repository: https://github.com/rsksmart/rif-marketplace-example

The goal of the project is to have a working demonstration of the RIF Marketplace Engine implemented with a front end.

Prerequisites for running locally:
- Docker
- thegraph-cli (https://github.com/graphprotocol/graph-cli) 
- Ganache CLI or an RSKj Node.

## Running the project connected to Testnet (Only accesible with the VPN)
1. Go to the `rif-marketplace-example` folder.
2. Ask in the `rif-marketplace-demo` slack channel for the latest .env file and paste it in the root folder.
3. Run `yarn start`

## Setting up a local environment

1. Clone the repositories
    - Clone the rif-marketplace-engine repository. (https://github.com/rsksmart/rif-marketplace-engine)
    - Clone the graph-node repository. (https://github.com/graphprotocol/graph-node)
2. Start a new Ganache instance by running `ganache-cli` on the terminal.
3. Deploy the RIF Marketplace Engine smart contracts.
    - In the rif-marketplace-engine project, go to the hardhat.config.js file and add the ganache network.
    ```json
    networks: {
        ...
        local: {
            url: "http://localhost:8545",
        },
    }
    ```
    - Deploy the smart contracts by running the following command in the root folder:
    ```
    npx hardhat run scripts/deploy.ts --network local
    ```
    - Wait for the script to finish and copy the addresses of the deployed contracts and paste them into the .env file of the rif-marketplace-example project. (If there is no .env file created, copy and paste the .env.sample file and replace the values)
4. Setup the graph-node
    - Clone the graph-node repository. (https://github.com/graphprotocol/graph-node)
    - Run `docker-compose up` inside the `docker` folder.
5. Deploy the subgraphs.
    - Clone the rif-marketplace-example repository. ( https://github.com/rsksmart/rif-marketplace-example)
    - Go to the `rif-marketplace-example/mkptsubgraph` folder.
    - Replace the contract addresses for the listing manager and the asset wrapper in the `subgraph.yaml` file, and specify the startBlock to 0
    ```yaml
    ...
     source:
      address: "<LISTING_MANAGER_CONTRACT_ADDRESS>"
      abi: AssetWrapper
      startBlock: 0
    ...
    
    source:
      address: "<ASSET_WRAPPER_CONTRACT_ADDRESS>"
      abi: AssetWrapper
      startBlock: 0
    ```
    - Run: `graph codegen`
    - Run: `graph build`
    - Run: `graph create rif-marketplace-engine --node http://localhost:8020`
    - Run: `graph deploy rif-marketplace-engine --ipfs http://localhost:5001 --node https://localhost:8020`
    - Copy the graph server URL and paste it into the .env file in the `REACT_APP_GRAPHQL_URL` property.

5. Configure the smart contracts.
    - Go to the `rif-marketplace-example` folder.
    - In the .env file set the `NETWORK_URL` property to `http://localhost:8545`
    - In the .env file set the `ACCOUNT_1` property to the first private key provided by ganache.
    - **NOTE If no other account is needed set the `ACCOUNT_2`, `ACCOUNT_3`, `ACCOUNT_4` and `ACCOUNT_5` variables to the same as `ACCOUNT_1`**
    - Run `node scripts/getNFT.js` and copy and paste the contract address from the output and paste it in the .env file in the `REACT_APP_NFT_ADDRESS` property.
    - Run `node scripts/getRIF.js` and copy and paste the contract address from the output and paste it in the .env file in the `REACT_APP_RIF_ADDRESS` property.
    - Run `node scripts/configuration.js`

6. Start the front end
    - Go to the `rif-marketplace-example` folder.
    - Run `yarn start`


## Metamask configuration

For local environment:
    - Network name: Ganache
    - New RPC URL: http://localhost:8545
    - Chain ID: 1337
    - Currency symbol: RBTC

For testnet: **(Only accesible with the VPN)**
    - Network name: Marketplace Node
    - New RPC URL: https://api.marketplace-example.testnet.rifos.org:4444
    - Chain ID: 31
    - Currency symbol: TRBTC 