Skip to main content
TLDR:
  • You’ll build and deploy a contract-based DApp that generates and verifies academic certificates on Ethereum.
  • You’ll use Truffle locally to create, test, and compile your contracts.
  • You’ll integrate with Chainstack to run your own Ethereum Sepolia node and migrate your contracts.
  • By the end, you’ll have a fully working certificate-issuing DApp ready for a testnet deployment.

Main article

In this tutorial, you will:
  • Create a DApp that generates an academic certificate.
  • Deploy the DApp on a public Ethereum node using Chainstack.
The contract and the Truffle configuration are in the GitHub repository.

Prerequisites

Overview

To get from zero to a deployed DApp on the Ethereum Sepolia testnet, do the following:
  1. With Chainstack, create a .
  2. With Chainstack, join the Ethereum Sepolia testnet.
  3. With Chainstack, access your Ethereum node credentials.
  4. With Truffle, create and compile the DApp contract.
  5. With Truffle, deploy the contract to your local development network.
  6. With Truffle, interact with the contract on your local development network.
  7. With Truffle, create and run the contract test.
  8. With Truffle, deploy the contract to your Ethereum node running with Chainstack.

Step-by-step

Create a public chain project

See Create a project.

Join the Ethereum Sepolia testnet

See Join a public network.

Get your Ethereum node access and credentials

See View node access and credentials.

Get Sepolia testnet ether from a faucet

In your MetaMask, fund each account with Sepolia ether from our Sepolia Ethereum faucet.

Create and compile the contracts

  1. On your machine, create a directory for the contract. Initialize Truffle in the directory:
    This will generate the Truffle boilerplate structure:
  2. Go to the contracts directory. In the directory, create two files: Ownable.sol and DocStamp.sol.
    This is an ownable contract. The contract implementation is the following:
    • Only an authority can generate a certificate. On contract deployment, the authority is the account that deploys the contract. The authority is the contract owner.
    • The contract owner can transfer their authority.
    This is the main contract. The contract handles the generation and verification of certificates.
    • issueCertificate() — generates a certificate by calculating a hash of the student name and details.
      • Can be called only by the owner.
      • Emits a certificate generation event with the timestamp.
      • The issuer puts the certificate on the blockchain by storing it in the global variable records by passing records[certificate] = msg.sender.
    • owningAuthority() — returns the address of issuer/authority.
    • verifyCertificate() — calculates a hash of the student name and details, and checks if the contract is on the blockchain.
      • Can be called by anyone.
  3. Create 2_deploy_contracts.js in the migrations directory.

    Deployment details

    Since DocStamp inherits from Ownable, Ownable will be deployed together with DocStamp.
  4. Compile the contracts:
    This will compile the contracts and put them in your build/contracts directory in the .json format. If the contract does not compile, check the compiler version in your truffle-config.js file and ensure that your compiler version matches the pragma solidity version of the contract.

Deploy the contract to your local development network

  1. Start the development network on your machine:
  2. Without exiting the Truffle console, deploy the contract to the local development network:
    This will deploy the contract to the development network as specified in thetruffle-config.js.

Interact with the contract on your local development network

  1. In your Truffle console, create an instance of the deployed contract:
    You can run instance to see the contract object ABI, bytecode, and methods.
  2. Declare the contract owner:
    You can run owner to see the account that deployed the contract and owns the contract.
  3. Issue the certificate:
    This issues the certificate. Run result.logs to view the full certificate details.

    Getting certificate details

    Running result will not print the certificate details in Truffle console. You must run result.logs.See also Processing transaction results.
    Example output:
    Note the record value in the output. This is the hash of the certificate values: name and details. You will need this hash to create the contract test later in this tutorial.
  4. Run the certificate verification:
    where
    • NAME — the student name on the certificate used on the issuing step.
    • DETAILS — any details
    • CERTIFICATE_HASH — the hash of DETAILS and NAME. You should have received this hash in the record field at the previous step by running result.logs.
    Example:
    Running verify will now print true if there is a match, and false if there is no match.

Test the contract

  1. Navigate to the test directory.
  2. Create a test.js file:
    where
    • NAME — the student name on the certificate used on the issuing step.
    • DETAILS — any details
    • CERTIFICATE_HASH — the hash of DETAILS and NAME. You should have received this hash in the record field at one of the previous steps by running result.logs.
    Example:
  3. Run the test:
    The test run output should be Passing.

Deploy the contract to your Ethereum node

  1. Install HDWalletProvider. HDWalletProvider is Truffle’s separate npm package used to sign transactions. Run:
  2. Edit truffle-config.js to add:
    • HDWalletProvider
    • Your Ethereum node access and credentials. Example:
    where
    • sepolia — any network name that you will pass to the truffle migrate --network command.
    • HDWalletProvider — Truffle’s custom provider to sign transactions
    • mnemonic — your mnemonic that generates your accounts. You can also generate a mnemonic online with Mnemonic Code Converter. Make sure you generate a 15-word mnemonic.
    • YOUR_CHAINSTACK_ENDPOINT — your Chainstack node endpoint. See View node access and credentials and Ethereum tooling.
    • network_id — the Ethereum Sepolia testnet network ID: 5.
  3. Run:
    This will engage 2_deploy_contracts.js and deploy the contract to the Ethereum Sepolia testnet as specified in truffle-config.js.

Get testnet ether

You must get the Sepolia testnet ether to deploy the contract to the testnet.

About the author

Ake

Ake Director of Developer Experience @ Chainstack
Talk to me all things Web3
20 years in technology | 8+ years in Web3 full time years experience
Last modified on April 13, 2026