TLDR:
In this tutorial, you will:
The contract and the Truffle configuration are in the GitHub repository.
To get from zero to a deployed DApp on the Ethereum Sepolia testnet, do the following:
With Chainstack, create a .
With Chainstack, join the Ethereum Sepolia testnet.
With Chainstack, access your Ethereum node credentials.
With Truffle, create and compile the DApp contract.
With Truffle, deploy the contract to your local development network.
With Truffle, interact with the contract on your local development network.
With Truffle, create and run the contract test.
With Truffle, deploy the contract to your Ethereum node running with Chainstack.
See Create a project.
See View node access and credentials.
In your MetaMask, fund each account with Sepolia ether from our Sepolia Ethereum faucet.
On your machine, create a directory for the contract. Initialize Truffle in the directory:
This will generate the Truffle boilerplate structure:
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.
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.
Create 2_deploy_contracts.js
in the migrations
directory.
Since DocStamp inherits from Ownable, Ownable will be deployed together with DocStamp.
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.
Start the development network on your machine:
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
.
In your Truffle console, create an instance of the deployed contract:
You can run instance
to see the contract object ABI, bytecode, and methods.
Declare the contract owner:
You can run owner
to see the account that deployed the contract and owns the contract.
Issue the certificate:
This issues the certificate.
Run result.logs
to view the full 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.
Run the certificate verification:
where
result.logs
.Example:
Running verify
will now print true
if there is a match, and false
if there is no match.
Navigate to the test
directory.
Create a test.js
file:
where
result.logs
.Example:
Run the test:
The test run output should be Passing
.
Install HDWalletProvider
.
HDWalletProvider is Truffle’s separate npm package used to sign transactions.
Run:
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 transactionsmnemonic
— 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.network_id
— the Ethereum Sepolia testnet network ID: 5
.Run:
This will engage 2_deploy_contracts.js
and deploy the contract to the Ethereum Sepolia testnet as specified in truffle-config.js
.
You must get the Sepolia testnet ether to deploy the contract to the testnet.
TLDR:
In this tutorial, you will:
The contract and the Truffle configuration are in the GitHub repository.
To get from zero to a deployed DApp on the Ethereum Sepolia testnet, do the following:
With Chainstack, create a .
With Chainstack, join the Ethereum Sepolia testnet.
With Chainstack, access your Ethereum node credentials.
With Truffle, create and compile the DApp contract.
With Truffle, deploy the contract to your local development network.
With Truffle, interact with the contract on your local development network.
With Truffle, create and run the contract test.
With Truffle, deploy the contract to your Ethereum node running with Chainstack.
See Create a project.
See View node access and credentials.
In your MetaMask, fund each account with Sepolia ether from our Sepolia Ethereum faucet.
On your machine, create a directory for the contract. Initialize Truffle in the directory:
This will generate the Truffle boilerplate structure:
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.
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.
Create 2_deploy_contracts.js
in the migrations
directory.
Since DocStamp inherits from Ownable, Ownable will be deployed together with DocStamp.
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.
Start the development network on your machine:
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
.
In your Truffle console, create an instance of the deployed contract:
You can run instance
to see the contract object ABI, bytecode, and methods.
Declare the contract owner:
You can run owner
to see the account that deployed the contract and owns the contract.
Issue the certificate:
This issues the certificate.
Run result.logs
to view the full 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.
Run the certificate verification:
where
result.logs
.Example:
Running verify
will now print true
if there is a match, and false
if there is no match.
Navigate to the test
directory.
Create a test.js
file:
where
result.logs
.Example:
Run the test:
The test run output should be Passing
.
Install HDWalletProvider
.
HDWalletProvider is Truffle’s separate npm package used to sign transactions.
Run:
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 transactionsmnemonic
— 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.network_id
— the Ethereum Sepolia testnet network ID: 5
.Run:
This will engage 2_deploy_contracts.js
and deploy the contract to the Ethereum Sepolia testnet as specified in truffle-config.js
.
You must get the Sepolia testnet ether to deploy the contract to the testnet.