How to Deploy a Token Authority on Oasis?
Last updated
Last updated
Read more about Oasis network here.
In this tutorial, we will be using Oasis Sapphire testnet as an example for the deployment. Oasis is just the first option we support, but in the future will be one of many.
Smart contract deployment on mainnet will need different network details.
On the date of making this document, the version of Solidity has to be 0.8.24 for smart contracts on Oasis Sapphire network.
Firstly, make sure you have added an Oasis testnet into your wallet. The network details are in the below picture and code block.
Secondly, get the test tokens through faucet provided by Oasis on this website.
Once you have received the tokens from Oasis Sapphire faucet, it will be shown on your wallet application as in the image below.
Keep in mind that, smart contracts that will be deployed on Oasis Sapphire would have to be adjusted in the way that Oasis recommends. The below example is the simplified version of Token Authority smart contract for this case.
It is important to inherit Oasis Sapphire into the smart contract that will be deployed on Oasis network. The code block below is the example of Oasis inheritance.
Using Remix for deploying smart contract on Oasis Sapphire does not require many more steps if the provider is set to Injected Provider. Remix can fetch the network details from wallet application like MetaMask. After that the deployment process would be similar to Sepolia testnet deployment.
One thing to keep in mind is that Use configuration file on Solidity compiler from the sidebar has to be ticked when compiling Token Authority.
The given compiler_config.json
which you need to put into Remix project is below this line. You may create your a new file if compiler_config.json
does not exist.
You can now compile the smart contract. A useful tip here is, Remix has a short-cut of CTRL + S
for compiling smart contract.
After compiling, you can now deploy Token Authority on Oasis Sapphire. There are two ways of deploying this contract.
The first one is to use the web-interface. For this case, ensure that you have selected the correct network in MetaMask. You will also need to fill the constructors of this Token Authority.
The second method is to use a script. We are going to use a script from default template of Remix IDE which is <deploy_with_ethers.ts>
. The below code block is the modified version of that default script. Constructors are also mandatory to be added in the code.
After deploying, verification of deployed smart contract on Oasis Sapphire can be done within Remix, you might have to activate the plugin from Sourcify in the Plugin manager from the sidebar menu.
This plugin requires the network name, deployed contract address, and the name of the contract which should be available in your interface.
First of all, make sure you have set up private key of the wallet that will be the one which deploys smart contract in .env
file as in the below example.
Secondly, install the relevant dependencies in the Hardhat project.
In the Hardhat config file, we have to add the Oasis Sapphire network as in the code block below. It is worth mentioning that in order to deploy Token Authority, Hardhat config file will need to set the viaIR
to true. Also, make sure you import the private key from .env
file properly.
After that, the smart contract can be compile using Hardhat compile.
Then, we can use a script in the project for deploying the smart contract as in the below code block. The script can be saved in the directory of scripts/<SCRIPT>
.
In this case, we name it as deploy.ts
.
The command-line for running script to deploy smart contract on Oasis Sapphire using Hardhat would be in the below attached.
After running this command-line, you might want to verify your smart contract afterwards.
If you wish to use the verification interface on Sourcify. The relevant file that might be required later is <metadata.json>
which can be found on project/artifacts/build-info/<your_solidity_file_name>.json
.
Another choice is to use Hardhat CLI, which can be done using the following code block.
At the moment, verifying deployed smart contract on Oasis Sapphire network using Hardhat CLI might show red error message as in the following figure. Even though, the terminal shows errors, the smart contract might already be verified. It is recommended to re-check with the deployed address on ABI Playground
Your .env
file might have to be refined for supporting Oasis Sapphire network as in the block below.
In Foundry project, it is important to install the dependencies so that it can perform proficiently. One of the example we can focus on is Openzeppelin Ownable which is from the above Example section. It can be installed using the below code line.
Also, it is good to know that we have to inherit Oasis Sapphire before deploying smart contracts into the Oasis network.
Using Foundry forge in the below block of code to install Oasis Sapphire SDK into the project. You might need to use the no commit CLI to install this SDK.
You might notice that <.gitmodules>
file in your project will have this part of Sapphire after installing the dependency.
Moreover, foundry.toml
needs to enable via_ir
for deploying Token Authority, as in the below code block.
Next, the Foundry project needs <remappings.txt>
for specify the Oasis Sapphire as in the given example below.
If this file already exist in your Foundry project, you may paste the given lines into your <remapping.txt>
.
If you do not have remappings.txt, you can manually create one and paste the given lines into that file.
Then, use the command-line below to remap Oasis into the proper approach.
The last but not least step here is to deploy. The CLI for deploying smart contract on Oasis Sapphire is below.
After running this command-line, you might want to verify your smart contract afterwards. The relevant file that might be required later is <metadata.json>
which can be found on project/out/Contract.sol/ContractName.json
. You might have to upload the Solidity contract file as well when you verify through Sourcify.
If you wish to use Foundry command-line to verify the contract, it natively supports verification on Sourcify.
After deploying smart contract to Oasis Sapphire network, you can access your smart contract on Oasis Explorer here. On Oasis Explorer, the suggested method of verifying deployed smart contract is to use Sourcify.
Keep in mind that if you wish to continue using the web-interface you will to upload the <metadata.json>
file, which is already compiled from the tool that you have used for deploying contract.
After verifying, we can now then see on Oasis Explorer, the deployed contract has been verified.
After successfully verified your contract, you can enter ABI playground for testing the smart contract through your browser.
It is worth mentioning that the Verification part on Oasis Explorer might not be updated accordingly to the verification from Sourcify. See the instruction for more details.
In case that the smart contract does not show as verified, there is a method to access ABI playground by substituting deployed contract address in the URL below.