Skip to content Skip to footer

Deploying the contract

 let’s go line by line:

cd backend; pnpm install; pnpm build;

First we need to  go to our backend folder and type in the pnpm install command which downloads all all the dependencies from the network from the internet

 And then we will run pmpm build

This build step will  compile our solidity smart contract written in the solidity language to the bytecode. The bytecode will then be executed by the ethereum virtual machine  inside  sapphire  and it will also produce some other things like the ABI the application binary interface this is like a list of all the functions your dApp or your browser can access and call.

Let’s break down what’s happening here:

Inside the contracts folder, you’ll find our Solidity contract. Alongside it, there’s an abi folder that was generated. This contains the Application Binary Interface (ABI). Let’s take a quick look—

it includes the setMessage function, which doesn’t return anything but accepts a single string as input.

This ABI is what your dApp compilers use to create a seamless interface in TypeScript. For example, you can simply call a function like setMessage in your app, and the rest happens behind the scenes. The transaction is generated, broadcast to the network, and processed, all without you needing to handle these complexities manually.

In the artifacts folder, there’s additional data for contract verification. If you’re planning to deploy a contract and verify it, this is the file you’ll need to upload to the verification service of your choice.

The contract is now compiled, let’s deploy it:

PRIVATE_KEY= 0x…; npx hardhat deploy –network sapphire–testnet

 There’s an environmental variable called private key where we will need to put the private key of our account and then the command is npx hardhat deploy and on Sapphire testnet

This is the address (595Cc) where our contract was deployed to and now if you want to communicate with our contract this is the address that we need to provide each time. We can now launch our Explorer and see if this is really the case and type in the address. There is no contact on the mainnet, which is expected , but there is one result on the testnet and if you click on the address you get some nice info like who created the address

There is one transaction related to this contract, the contract creation transaction. It is in plain format, not encrypted as shown by the gray padlock.

This plain format is sapphire specific. . This is not anywhere inside ethereum. It is the end to end encryption I talked about previously so the contract creation  transaction in our case was not encrypted.

In the next lesson we will look into confidential transaction