Smart Contract Digital Certificate

How to Install Digital Certificate on Smart Contract

This tutorial covers digital certificate installation for Solidity smart contracts.

Pre-requisite

Before you can install your digital certificate on your smart contract, you need to perform the activation process where we will issue you the certificate after activation. Once you receive your digital certificate, you may begin the installation process as below.

TL;DR

Below is a video tutorial that explains it all.

#1. You Need To Activate Your Certificate

To activate your certificate, go to your account page, and click on the Order menu. Then, click on the View button to view your order.

How to activate certificate - Step 1

After clicking on the View button, you will be able to see the activation form. Fill in the form with your details and your smart contract information.

Please ensure that you enter the same smart contract name that you will be using when deploying your contract as well as the same wallet address that you will use to deploy.

How to activate certificate - Step 2

Once you have filled in the activation form, we shall verify your information and issue your certificate. You will be notified via email once your certificate is ready.

#2. Download Your Certificate

Once your smart certificate is ready, go to your account page and click on the Certificates menu. You will be able to see a Download Certificate button. Click on the button to download your public digital certificate. Here’s a sample of a certificate in PEM format.

How to activate certificate - Step 3

#3. Copy Your Digital Certificate ASCII Text

Your certificate file should be a .pem file containing Base64 ASCII text. It is a PEM encoded certificate. You may open the file using any typical text editor, such as Notepad (Windows) or TextEdit (Mac).

In the file, you should copy the ASCII text that represents your certificate. It looks something like below.

-----BEGIN CERTIFICATE-----
MIIFhzCCBG+gAwIBAgIIFNTFi4cf6ogwDQYJKoZIhvcNAQELBQAwfDEYMBYGA1UE
CgwPWnRhbXAgUHRlLiBMdGQuMRkwFwYDVQQKDBBodHRwczovL3p0YW1wLmlvMRkw
FwYDVQQDDBBadGFtcCBJc3N1aW5nIENBMR0wGwYJKoZIhvcNAQkBFg5oZWxsb0B6
dGFtcC5pbzELMAkGA1UEBhMCU0cwHhcNMjMwOTIzMDEwMjQzWhcNMjQwOTIyMDEw
MjQzWjCB3zEUMBIGA1UECgwLaVRva2VuIEluYy4xDzANBgNVBAMMBmlUb2tlbjEe
MBwGCSqGSIb3DQEJARYPam9obkBpdG9rZW4uY29tMRQwEgYDVQQHDAtMb3MgQW5n
ZWxlczETMBEGA1UECAwKQ2FsaWZvcm5pYTELMAkGA1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AgU21hcnQgQ29udHJhY3QgQ2VydGlmaWNhdGUgUG9saWN5MA0GCSqGSIb3
DQEBCwUAA4IBAQBPxrgMZAIsAfiysOuVTtGUmSJXTTxRj4+6kRfzBEmtHgCdH8mF
HhDqTpVwQLe3Bqli4V+qRcQyXOpnY+QnPeYh3gJzVpHinn+DyBjmH9GwpditWKJ3
sFC2k53cJJDbGo90Dvw4758yle0GxSSXTUW970NB6XwqeVPePCvfUXs9q5vT29g7
VJpl2fd0R9ZzaDnsRLg9mV3Mmet/PWgwncM5uKKIR+zqJRgO9tEncN/YPmrs8dbP
XrgW1czjogb9hStBvI1G6Ap8fCEY8VWzQikcXkRAXFv/nmEi1y+gvsliuEr2allN
cD1jUZ0fkD9NCQEjdI1U3lAWQF3YAeZuXZtv
-----END CERTIFICATE-----

IMPORTANT: Please ensure you copy the-----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- as well.

#4. Format Your Digital Certificate

Your smart contract certificate is essentially an X.509 certificate. The funny thing about this digital certificate format is that it comes with line breaks at every 64th character. You need to replace the line breaks with \n.

To do this, you can use the search and replace function on Coding Tools website. Below are the steps.

  1. Paste your certificate ASCII code.
  2. Enter \n in the “regular expression” input field and \n in the “replace to” input field.
  3. Press the “Regex Replace” button.
  4. Then, press “Copy Result” button to copy the new certificate ASCII text.

View the screenshot below. Once done, your certificate ASCII text should appear as one single line.

Replace line breaks in digital certificate

#5. Include Your Certificate in Your Smart Contract, Then Compile and Deploy

Let’s move to your smart contract. In your Solidity contract code, you need to have a public variable called certificate with string datatype. Then, assign your digital certificate one-line ASCII code to this variable. Below is an example of using an ERC721 NFT smart contract code that is also available on our GitHub.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyNFT is ERC721, Ownable {

   string public certificate; // String public variable for certificate

   constructor() ERC721("MyNFT", "MNFT") {

      // Assign certificate variable with your certificate ASCII code in one line
      certificate =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r\nBgEFBQcDAzAdBgNVHQ4EFgQU5Eic7fmA4XdpblBp4tkQmjptn18wHwYDVR0jBBgw\nFoAUAK2tZoc0HL4ZoxcAEJi09hp1/F4wLwYIKwYBBQUHAQEEIzAhMB8GCCsGAQUF\nBzAChhNodHRwczovL3p0YW1wLmlvL2NhMDMGA1UdHwQsMCowKKAmoCSGImh0dHBz\nOi8venRhbXAuaW8vY2EvaXNzdWluZy1jYS5jcmwwgccGA1UdIASBvzCBvDBzBgor\nBgEEAYPbTQEBMGUwIwYIKwYBBQUHAgEWF2h0dHBzOi8venRhbXAuaW8vY2EvY3Bz\nMD4GCCsGAQUFBwICMDIaMFp0YW1wIFB0ZS4gTHRkLiBDZXJ0aWZpY2F0aW9uIFBy\nYWN0aWNlIFN0YXRlbWVudDBFBgorBgEEAYPbTQIBMDcwNQYIKwYBBQUHAgIwKRon\nWnRhbXAgU21hcnQgQ29udHJhY3QgQ2VydGlmaWNhdGUgUG9saWN5MA0GCSqGSIb3\nDQEBCwUAA4IBAQBPxrgMZAIsAfiysOuVTtGUmSJXTTxRj4+6kRfzBEmtHgCdH8mF\nHhDqTpVwQLe3Bqli4V+qRcQyXOpnY+QnPeYh3gJzVpHinn+DyBjmH9GwpditWKJ3\nsFC2k53cJJDbGo90Dvw4758yle0GxSSXTUW970NB6XwqeVPePCvfUXs9q5vT29g7\nVJpl2fd0R9ZzaDnsRLg9mV3Mmet/PWgwncM5uKKIR+zqJRgO9tEncN/YPmrs8dbP\nXrgW1czjogb9hStBvI1G6Ap8fCEY8VWzQikcXkRAXFv/nmEi1y+gvsliuEr2allN\ncD1jUZ0fkD9NCQEjdI1U3lAWQF3YAeZuXZtv\n-----END CERTIFICATE-----";

   }

   function updateCert(string memory cert) public onlyOwner {
      certificate = cert;
   }
}

Do not forget to include the updateCert function to allow you to change your certificate in the future. Once done, you may compile and deploy your smart contract on the blockchain.

#6. Read The Digital Certificate of Your Smart Contract

To ensure everything runs smoothly, go ahead and read the certificate variable to ensure it returns the certificate ASCII code. If yes, your smart contract is now certified with your ownership!

Now, supported block explorers and wallets shall be able to read your smart contract certificate.