Ethereum Tooling
On this page
Remix: Deploying a Smart Contract #
Learn how to deploy a simple Solidity-based smart contract to ICPlaza using the Remix in-browser IDE {synopsis}
Remix is an in-browser IDE for Solidity smart contracts. In this guide, we will learn how to deploy a contract to a running ICPlaza network through Remix and interact with it.
Connect to Remix #
::: tip If you haven’t already, follow the steps in the Metamask guide to import your ICPlaza private key into Metamask. Start the ICPlaza daemon and REST server. :::
Go to Remix. There are some contracts in the File Explorer. Replace these with the source code to Counter.sol below. On the left-most bar, select the Solidity Compiler and compile the contract.
Next, select the Deploy and Run option. Select Injected Web3 as the Environment. This will open a metamask popup for you to connect your Metamask to Remix. Select Connect to confirm.
You should see your account show up in the left-hand panel.
Deploy and Interact #
Now that your account is connected, you are able to deploy the contract. Press the Deploy button. A metamask pop-up will appear asking you to confirm. Confirm the transaction. You should see a log for the deployment transaction in the ICPlaza daemon logs:
Once the contract has been successfully deployed, you will see it show up in the Deployed Contracts section in the left-hand side, as well as a green check in the Remix console showing the transaction details.
Now, you are able to interact with the contract through Remix. For Counter.sol, click add. This will open a Metamask pop-up asking you to confirm. Confirm the transaction. Then, click getCounter to get the count, which should be 1.
Hardhat: Deploying a Smart Contract #
Learn how to deploy a simple Solidity-based smart contract to ICPlaza using the Hardhat environment {synopsis}
Hardhat is a flexible development environment for building Ethereum-based smart contracts. It is designed with integrations and extensibility in mind
Install Dependencies #
Before proceeding, you need to install Node.js (we’ll use v16.x) and the npm package manager. You can download directly from Node.js or in your terminal:
:::: tabs ::: tab Ubuntu
::: ::: tab MacOS
::: ::::
You can verify that everything is installed correctly by querying the version for each package:
Create Hardhat Project #
To create a new project, navigate to your project directory and run:
Following the prompts should create a new project structure in your directory. Consult the Hardhat config page for a list of configuration options to specify in hardhat.config.js. Most importantly, you should set the defaultNetwork entry to point to your desired JSON-RPC network:
:::: tabs ::: tab Local Node
::: ::: tab Testnet
::: ::::
To ensure you are targeting the correct network, you can query for a list of accounts available to you from your default network provider:
Deploying a Smart Contract #
You will see that a default smart contract, written in Solidity, has already been provided under contracts/Greeter.sol:
This contract allows you to set and query a string greeting. Hardhat also provides a script to deploy smart contracts to a target network; this can be invoked via the following command, targeting your default network:
Hardhat also lets you manually specify a target network via the --network <your-network> flag:
:::: tabs ::: tab Local Node
::: ::: tab Testnet
::: ::::
Finally, try running a Hardhat test:
Truffle: Deploying a Smart Contract #
Learn how to deploy a simple Solidity-based smart contract to ICPlaza using the Truffle environment {synopsis}
Truffle is a development framework for deploying and managing Solidity smart contracts.
Install Dependencies #
First, install the latest Truffle version on your machine globally.
Create Truffle Project #
In this step we will create a simple counter contract. Feel free to skip this step if you already have your own compiled contract.
Create a new directory to host the contracts and initialize it:
Initialize the Truffle suite with:
Create contracts/Counter.sol containing the following contract:
Compile the contract using the compile command:
Create test/counter_test.js containing the following tests in Javascript using Mocha:
Truffle configuration #
Open truffle-config.js and uncomment the development section in networks:
This will allow your contract to connect to your ICPlaza local node.
Deploy contract #
In the Truffle terminal, migrate the contract using:
You should see incoming deployment logs in the ICPlaza daemon Terminal tab for each transaction (one to deploy Migrations.sol and the other to deploy Counter.sol).
Run Truffle tests #
Now, you can run the Truffle tests using the ICPlaza node using the test command:
Last updated