Skip to content
Prividium

Deploying Contracts

The guides in this section will show you how to:

  1. Deploy an ERC20 token contract on Prividium.
  2. Programmatically configure contract permissions through the permission API.
  3. Interact with your contract in a script.
  4. Build a frontend to interact with the contract.

This guide assumes you already have either a local instance of Prividium running on your machine or contract deployment permissions for a live Prividium network.

Authentication options

We recommend using the prividium proxy command to deploy and interact with contracts. This proxy handles all the authentication required for you to deploy and interact with contracts.

Alternatively, you may handle authentication yourself inside a custom script. You will see how both options work in this guide.

Project setup

Create a new project folder and move into the folder in your terminal.

mkdir hardhat-prividium-example
cd hardhat-prividium-example

Initialize a new Hardhat 3 project with Node Test Runner with viem. Select y to install the dependencies.

npx hardhat --init

Next, install the OpenZeppelin contracts package.

npm
npm install -D @openzeppelin/contracts

Configuring the network

Add the Prividium network you will use to the hardhat.config.ts file and configure the ignition required confirmations.

hardhat.config.ts
    ignition: {
        requiredConfirmations: 1
    },
    networks: {
        localPrividium: {
            type: 'http',
            chainType: 'generic',
            // npx prividium proxy url, signed in via local prividium
            // use npx prividium proxy -u http://localhost:3001 -r http://localhost:8000/rpc
            url: 'http://127.0.0.1:24101/rpc',
            // local prividium account
            // WARNING: never save your private key for a mainnet/testnet wallet here
            accounts: ['0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80']
        },
        testnetPrividium: {
            type: 'http',
            chainType: 'generic',
            // npx prividium proxy url, signed in via testnet
            // use npx prividium proxy -u <USER_PANEL_URL> -r <RPC_URL>
            url: 'http://127.0.0.1:24101/rpc',
            // https://hardhat.org/docs/guides/configuration-variables
            accounts: [configVariable('PRIVIDIUM_PRIVATE_KEY')]
        }
    }

The localPrividium network is configured to use the default admin private key for a local network started with local-prividium. Otherwise if you are planning to use a live deployed network, make sure to configure the PRIVIDIUM_PRIVATE_KEY with Hardhat keystore.

Create the token contract

Create a new file in the contracts folder called QuickstartToken.sol.

touch contracts/QuickstartToken.sol

Copy and paste the QuickstartToken contract below into the QuickstartToken.sol file.

QuickstartToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

contract QuickstartToken is ERC20, Ownable, ERC20Burnable {
    constructor(string memory name, string memory symbol) ERC20(name, symbol) Ownable(msg.sender) {
        _mint(msg.sender, 100 * 10 ** decimals());
    }

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

This contract:

  • Imports helper contracts from @openzeppelin/contracts so that our contract is a standard ERC-20 contract, has an owner, and allows tokens to be burned
  • Sets the token name and symbol using the constructor arguments
  • Sets the deployer wallet as the owner
  • Mints an initial supply of tokens to the deployer
  • Only allows the owner to mint additional tokens using the mint function

Create the deploy script

Create a new file in the ignition/modules folder called QuickstartToken.ts. This file will be used to deploy the token contract.

touch ignition/modules/QuickstartToken.ts

Copy and paste the ignition module below into QuickstartToken.ts. This will be used to deploy the contract.

QuickstartToken.ts
import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';

export default buildModule('QuickstartToken', (m) => {
    const quickstartToken = m.contract('QuickstartToken', ['Quickstart Token', 'QKT']);

    return { quickstartToken };
});

Setting up the proxy

Log in to the user panel with an admin account or an account with contract deploy permissions. For a local Prividium, go to http://localhost:3001 and use the Keycloak login admin@local.dev with the password password.

Start the local proxy and keep it running.

Local prividium:

npx prividium proxy -u http://localhost:3001 -r http://localhost:8000/rpc

Testnet prividium:

npx prividium proxy -u <USER_PANEL_URL> -r <RPC_URL>

Deploy the contract

Compile and deploy the contract. Your contract address will be logged in the output.

npx hardhat compile

Deploy to either localPrividium or testnetPrividium:

npx hardhat ignition deploy ignition/modules/QuickstartToken.ts --network localPrividium
npx hardhat ignition deploy ignition/modules/QuickstartToken.ts --network testnetPrividium

You should see the contract address logged in your console. Now the contract is deployed on your Prividium network! In the next section, you will learn how to configure the contract permissions.