This repo is based off the starter project to build IBC enabled Solidity contracts that connect rollups to one another Polymer Hub, through the vIBC core contracts.
The repository is a GitHub template repository so you can click "Use this template" to create your own project repository without having the entire commit history of the template.
There's some basic information here in the README but a more comprehensive documentation can be found in the official Polymer documentation.
The repo is compatible with both Hardhat and Foundry development environments.
- Have git installed
- Have node installed (v18+)
- Have Foundry installed (Hardhat will be installed when running
npm install
) - Have just installed (recommended but not strictly necessary)
You'll need some API keys from third party's:
- Optimism Sepolia and Base Sepolia Blockscout Explorer API keys
- Have an Alchemy API key for OP and Base Sepolia
Some basic knowledge of all of these tools is also required, although the details are abstracted away for basic usage.
To compile your contracts and start testing, make sure that you have all dependencies installed.
From the root directory run:
just install
to install the vIBC core smart contracts as a dependency.
Additionally Hardhat will be installed as a dev dependency with some useful plugins. Check package.json
for an exhaustive list.
Note: In case you're experiencing issues with dependencies using the
just install
recipe, check that all prerequisites are correctly installed. If issues persist with forge, try to do the individual dependency installations...
Convert the .env.example
file into an .env
file. This will ignore the file for future git commits as well as expose the environment variables. Add your private keys and update the other values if you want to customize (advanced usage feature).
cp .env.example .env
This will enable you to sign transactions with your private key(s). If not added, the scripts from the justfile will fail.
The configuration file is where all important data is stored for the just commands and automation. We strive to make direct interaction with the config file as little as possible.
By default the configuration file is stored at root as config.json
.
However, it is recommended to split up different contracts/projects in the same repo into different config file in case you want to switch between them.
Store alternate config files in the /config directory and set
# .env file
CONFIG_PATH='config/alt-config.json'
to use a different config file.
The account associated with your private key must have both Base Sepolia and Optimism Sepolia ETH. To obtain the testnet ETH visit:
The project adds two smart contracts IbcBallot and IbcProofOfVoteNFT which enables functionality to vote on one chain, and then send a packet providing the proof of vote and mints and NFT on the destination chain.
git clone https://github.com/kenobijon/nft-vote-polymer.git
cd nft-vote-polymer
just install
There's also a just recipe that quickly enables to try to send packets over a custom IBC channel. Custom IBC channel require a channel hanshake to open a private IBC channel (which can take a while depending on the client latency) but then give complete control over a private IBC channel that enables fault isolation from other applications, compared to unviersal channels.
To have your application be compatible with custom IBC channels, have it inherit the CustomChanIbcApp base contract.
Run the following command to go through a full E2E sweep of the project, using the default XCounter.sol contract:
# Usage: just do-it
just nft-do-it
It does the following under the hood:
# Run the full E2E flow by setting the contracts, deploying them, creating a channel, and sending a packet
# Usage: just do-it
nft-do-it UNIVERSAL='false':
echo "Running the full E2E flow..."
just set-contracts optimism IbcBallot false && just set-contracts base IbcProofOfVoteNFT false
npx hardhat run scripts/deployBallot.js --network optimism
npx hardhat run scripts/deployNFTVote.js --network base
just sanity-check
just create-channel
just send-vote optimism
echo "You've done it!"
It makes sure you've got the correct contracts set, deploys new instances, creates a channel and sends a packet over the channel once created.
Note: by default the sim-client is used to improve latency. This is useful for iterative development and testing BUT also insecure as it involves no proofs. Make sure to move to the client with proofs by running another just command...
# Usage: just switch-client
just switch-client
Check if the packet got through on the Polymer IBC explorer.
The main work for you as a developer is to develop the contracts that make up your cross-chain logic.
You can use the contracts in the "/contracts/base" directory as base contracts for creating IBC enabled contracts that can either send packets over the universal channel or create their own channel to send packets over.
A complete walkthrough on how to develop these contracts is provided in the official Polymer documentation.
When the contracts are ready, you can go ahead and interact with the contracts through scripts. There is a Justfile to for the most common commands, with the underlying scripts in the /scripts folder.
The /private
folder within the scripts folder has scripts that you're unlikely to need to touch. The only scripts you'll (potentially) be interacting with are:
There's three types of default scripts in the project:
- The
deploy.js
allows you to deploy your application contract. You may want to add additional deployment logic to the Hardhat script. - In the
/contracts
folder you'll findarguments.js
to add your custom constructor arguments for automated deployment with thedeploy.js
script. - The
send-packet.js
script sends packets over an existing custom channel, andsend-universal-packet.js
is specifically for sending packets over a universal channel. You might want to add additional logic before or after sending the packet to cusotmize your application.
For most of the actions above and more, there are just recipes that combine related logic and update the configuation file in an automated way.
Note: These are the default scripts provided. They provide the most generic interactions with the contracts to deploy, create channels and send packets. For more complicated use cases you will want to customize the scripts to your use case. See advanced usage for more info.
Before deploying, make sure to update the config.json with your contract type to deploy for each of the chain you wish to deploy to.
Do this by running:
# Usage: just set-contracts [chain] [contract_type] [universal]
just set-contracts optimism MyContract true
to deploy MyContract artefact to the Optimism (Sepolia) chain.
IMPORTANT: This is where you set if your contract uses universal or custom channels. Make sure this corresponds to the base contract you've inherited from when developing your application (UniversalChanIbcApp or CustomChanIbcApp).
Then run:
# Usage: just deploy [source] [destination]
just deploy-ballot optimism
just deploy-nft base
where the script will automatically detect whether you are using custom or universal IBC channels.
The script will take the output of the deployment and update the config file with all the relevant information.
Before moving on, you'll want to check if the variables in your .env and config files line up with what is stored in the actual deployed contracts... especially when you're actively playing around with different configuration files and contracts.
To do a sanity check, run:
# Usage: just sanity-check
just sanity-check
If you're using universal channels, channel creation is not required. Your contract will send and receive packet data from the Universal channel handler contract which already has a universal channel to send packets over. You can directly proceed to sending (universal) packets in that case.
To create a custom channel, run:
just create-channel
This creates a channel between base and optimism. Note that the ORDER MATTERS; if you picked optimism as the source chain (first argument) above, by default it will create the channel from optimism and vice versa.
The script will take the output of the channel creation and update the config file with all the relevant information.
Check out the channel tab in the explorer to find out if the correct channel-id's related to your contracts were updated in the config.
Finally Run:
# Usage: just send-packet
just send-vote optimism
to send a packet over a channel (script looks at the config's isUniversal flag to know if it should use the custom or universal packet). You can pick either optimism or base to send the packet from.
As a starter value, the sim-client is used to improve latency. The sim-client is useful for iterative development and testing BUT also insecure as it involves no proofs. Make sure to move to the client with proofs by running another just command...
# Usage: just switch-client
just switch-client
This will use the op-stack client with proofs, making sure that the relayer is proving what is being submitted every step along the way, ensuring there's no trust assumption on the relayer.
An overview of the different clients can be found in ibc.json
:
{
"optimism": {
"sim-client": {
"canonConnFrom": "connection-0",
"canonConnTo": "connection-1",
"universalChannel": "channel-10"
},
"op-client": {
"canonConnFrom": "connection-8",
"canonConnTo": "connection-9",
"universalChannel": "channel-16"
}
},
"base": {
"sim-client" : {
"canonConnFrom": "connection-4",
"canonConnTo": "connection-5",
"universalChannel": "channel-11"
},
"op-client": {
"canonConnFrom": "connection-10",
"canonConnTo": "connection-11",
"universalChannel": "channel-17"
}
}
}
For advanced users, there's multiple custimizations to follow. These includes configuring the config.json manually and/or running the scripts without using just.
For example, the last action to send a packet on a universal channel could be executed with this command:
npx hardhat run scripts/send-universal-packet.js --network base
To send a universal packet from the contract specified in the config.sendUniversalPacket field in the config.
We welcome and encourage contributions from our community! Hereβs how you can contribute.
Take a look at the open issues. If there's an issue that has the help wanted label or good first issue, those are up for grabs. Assign yourself to the issue so people know you're working on it.
Alternatively you can open an issue for a new idea or piece of feedback.
When you want to contribute code, please follow these steps:
- Fork the Repository: Start by forking this repository.
- Apply the improvements: Want to optimize something or add support for additional developer tooling? Add your changes!
- Create a Pull Request: Once you're ready and have tested your added code, submit a PR to the repo and we'll review as soon as possible.
Feel free to open an issue for questions, suggestions, or discussions related to this repository. For further discussion as well as a showcase of some community projects, check out the Polymer developer forum.
Thank you for being a part of our community!