Deploying a smart contract can seem intimidating, but with the right knowledge and tools you’ll see how easy it is to get started. In this guide, we will cover the basics of deploying contracts on Mantle. We’ll begin by explaining the necessary tools, how to compile and deploy your contracts, and finally how to interact with your deployed contract.
This tutorial will be using the Remix IDE. That means you can follow along from any browser that has MetaMask installed. If you haven’t installed MetaMask, acquired $BIT tokens from our faucet, or added Mantle as a recognized network, please first complete our Complete Onboarding Guide. If you’ve already bridged tokens to Mantle, you’re ready for the tutorial!
When we first enter into Remix, it can seem like there is an overwhelming amount of information on the page. That’s why before we begin, let’s take some time to better understand Remix’s interface.
There are four components to Remix’s layout:
Side Panel: An interface that can switch between a file explorer, contract compiler, deployment interface, and a debugger.
Icon Panel: Acts as a menu to change the contents of the side panel.
Main Panel: Contains the primary view for editing our contracts and debugging.
Terminal: An interface to read the results of execution and traces.
Now that we understand the layout, let’s click back into the main file explorer. You’ll see that in our default workspace, Remix will have supplied us with 3 contracts: Storage, Owner, and Ballot.
Let’s start off by clicking on Storage.sol.
Storage.sol is a very simple contract that only has two available actions:
Stores a number on-chain via function “store”
Reads said stored number via function “retrieve”
As this tutorial is about deployment (and not Solidity), we’ll use this default contract in our workflow. To compile the contract click on the Solidity icon on the left navigation bar, and hit compile.
If there are any errors, they will appear at the bottom. For example:
Now that we’ve compiled our contracts, we can deploy them on Mantle Testnet. Select the deploy icon on the left, choose your environment to be “Injected Provider — MetaMask”, and click “Deploy”. (Important: Make sure you’ve chosen your network on MetaMask to be “Mantle Testnet”.)
You should be greeted with a popup like so:
Click “Confirm” to deploy your contract. And congratulations! You’ve deployed a contract onto Mantle Testnet! 🎉🎉
The “deployed contracts” section should be populated with more information. If you expand the contract, you can interact with the contract directly on Remix.
Let’s interact with the contract via Remix. Enter a number into the textbox beside “store”, and click on the “store” button. Since this is a state mutating function, we will need to pay some $BIT to perform the transaction.
Once the transaction has gone through, clicking on “retrieve” should return on the number we inserted into the textbox above.
We can use the Mantle block explorer to understand more information about our contract and its deployment. Going back to the deployment interface, you copy the address as shown below.
Then, go to Mantle explorer, paste the address in the search bar and click on search.
It may take a few seconds for information to update after contract deployment. You should see here the details of your deployment transaction, as well as any transactions you submitted when interfacing with the contract through Remix.
Inspecting the contract address on the explorer also shows us that we have performed two transactions:
To create the contract
To change the stored value
If you feel like playing around with the explorer a little more, then you can also try copying your MetaMask wallet address to check the various transactions, deposits, withdrawals and more!
Congrats on deploying your very first contract on Mantle Testnet!
We’ve covered the basic onboarding by setting up the MetaMask and adding Mantle Testnet to it, followed by getting gETH and $BIT token for smart contract deployment. After deploying, we interacted with the contract with mutation function (storing a value).
We even covered explorer basics by confirming that the smart contract was actually deployed on testnet, and inspecting the various transaction calls that we made.
Hoping this walkthrough was a good start to getting onboarded to the Mantle’s current testnet. We encourage everyone to start building cool dApps on Mantle Testnet and reach out to our team with demos and questions!
Soon we will be covering more advanced ways to build, test, deploy, and interact your contracts with such tools as Forge and ethers.js, so stay tuned!