InstallationBack End Installation

Back End Installation

This section walks you through setting up the backend for ArtVault, which contains the smart contracts and blockchain configuration.

App Structure

2_node_deploy_contracts.js
package.json
truffle-config.js

Each part plays a specific role:

  • contracts/: Contains the Smart Contracts, the core logic for the NFTs.
  • migrations/: Defines how contracts are deployed on networks.
  • truffle-config.js: Specifies networks (like Ganache) and compiler version

Important: You can skip this section and use our Deployment playround directly instead of manual installation Visit Deployment Playground

1. Install Dependencies

inside the root of /backend directory, run the following command to install the required packages:

pnpm install

2. Modify truffle-config.js

Open truffle-config.js and ensure the following lines are present:

const HDWalletProvider = require('@truffle/hdwallet-provider');

/* ADD YOUR WALLET SECRET PASSPHRASE */
const mnemonic = 'Here goes your secret passphrase';

module.exports = {
    contracts_build_directory: 'client/src/contracts',

    /* SUPPORTED NETWORKS BY OUR APP [BOTH MAINNET AND TESTNET] */
    networks: {
        /* LOCAL DEVELOPMENT NETWORK - REQUIRES GANACHE:
            - To deploy contracts on this network, run this command in the root directory:
                truffle migrate --reset
        */
        development: {
            host: '127.0.0.1',
            port: 8545,
            network_id: '*',
        },

        /* CELO ALFAJORES TEST NETWORK: 
            - To deploy contracts on this network, run this command in the root directory: 
                truffle migrate --network celotestnet --reset
        */
        celotestnet: {
            provider: function () {
                /* the following line config is 
                    new HDWalletProvider(Metamask-secret-passphrase, RPC-URL, index-of-depolyer-account-in-Metamask, i.e. 0 means the first acoount)
                */
                return new HDWalletProvider(
                    mnemonic,
                    'https://alfajores-forno.celo-testnet.org',
                    0
                );
            },
            network_id: 44787,
        },
    },

    // Configure your compilers
    compilers: {
        solc: {
            version: '0.8.18',
        },
    },
};

3. Deployment Script Configuration

Before running the contract deployment script, you need to manually update two key configuration values at 2_node_deploy_contracts.js:

1. privateKey (🔑 Your Wallet's Private Key)

This is the private key of the Ethereum account that will deploy the contracts.

const privateKey = `Add your account's private key here`;

⚠️ Warning: Never share your private key publicly. Make sure it's stored securely. In production, consider using environment variables or secret management tools instead of hardcoding.

2. commission (💸 Marketplace Fee)

This value represents the commission percentage that the marketplace contract will take from each transaction.

const commission = 10; // Marketplace commission (e.g. 10%)
  • You can change this to any number (e.g. 5 means 5%)

  • It will be passed to the NFTMarketplace contract constructor during deployment

Example (Updated)

const privateKey = '0xabc123...'; // Replace with your actual private key
const commission = 5; // Set commission to 5%

4. Deploy Smart Contracts

If you want to test the app locally before deploying to a mainnet or a testnet, you can use Ganache. Follow these steps:

  1. Open Ganache and create a new workspace.
  2. Make sure the workspace is running on port 8545.
  3. Import acounts from Ganache to your Crypto wallet.
  4. In the /backend directory of the project, run the following command to deploy the contracts:
truffle migrate --network development --reset

If you want to run the app on a mainnet or a testnet. Follow these steps:

  1. Open truffle-config.js and search for your desired Network.
  2. If you don't find it, you can add it as following.
polygon: {
    provider: () =>
        new HDWalletProvider(mnemonic, `https://polygon-rpc.com`),
    network_id: 137,
},
  1. Run the migration command on this network
truffle migrate --network your-network-name --reset

After the depolyment finished, a new file is generated at the root directory of the app called /delpyed-contracts.json. We will need this in the next step.

6. Add to .env File

Modify the following environment variables to your .env file with the generated contracts.json file

NEXT_PUBLIC_COLLECTION_CONTRACT_ADDRESS='user-contract-address'
NEXT_PUBLIC_COLLECTION_CONTRACT_ADDRESS='nft-collection-contract-address'
NEXT_PUBLIC_MARKETPLACE_CONTRACT_ADDRESS='marketplace-contract-address'