Skip to content

Template starter for IBC enabled contracts in Solidity for use with vibc-core-smart-contracts

Notifications You must be signed in to change notification settings

tmsdkeys/x-ballot-nft

 
 

Repository files navigation

Template for IBC enabled Soldity contracts

This repo provides a starter project to build IBC enabled Solidity contracts that connect rollups to one another Polymer Hub, through the vIBC core contracts.

The repo is compatible with both Hardhat and Foundry development environments.

Find more information on building with (v)IBC and Polymer in the Polymer documentation.

Install dependencies

To compile your contracts and start testing, make sure that you have all dependencies installed.

From the root directory run:

forge install

to install the vIBC core smart contracts as a dependency.

Again from root, run:

npm install

to install some node modules as dependencies, specifically when you want to use Hardhat.

Set up your environment variables

In the .env file (you'll find it as .env.example), add your private key(s) and rename to drop the "example" in the filename. The dispatcher addresses should be correct but you could use custom ones if required.

Next, check the config.json file. This is where a lot of the parameters you need to deploy, create channels and send packets are stored.

When using the default scripts, those fields will be mostly auto-populated. Only the contract types in the deploy field must be updated when you write your own contracts.

Run the scripts

There's three types of scripts in the project:

  • deploy.js and deploy-config.js allow you to deploy your application contract
  • create-channel.js and create-channel-config.js creates a channel
  • send-packet.js sends packets over an existing custom channel, and send-universal-packet.js is specifically for sending packets over a universal channel

For every script you'll find a field in the config.json!!

Deploy

Run:

# format node scripts/deploy-config.js [source] [destination] [universal-channel-bool]
node scripts/deploy-config.js optimism base true

for an application that will use a universal channel, or:

# or 
node scripts/deploy-config.js optimism base false

for an application that uses custom channels.

To deploy instances of the contracts on optimism as the source and base as the destination chains. (You can also switch the order)

Also this script will take the output of the deployment and update the config file with all the relevant information.

Create a channel

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:

node scripts/create-channel-config.js

To create 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.

Also this 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.

Send packets

Finally Run:

npx hardhat run scripts/send-universal-packet.js --network optimism

to send a packet over a universal channel. You can pick either optimism or base to send the packet from.

Or run:

npx hardhat run scripts/send-packet.js --network optimism

to send a packet over a custom channel. You can pick either optimism or base to send the packet from.

NOTE Make sure to align the --network flag value to be compatible with your config values either on optimism or base.

About

Template starter for IBC enabled contracts in Solidity for use with vibc-core-smart-contracts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Solidity 54.7%
  • JavaScript 38.7%
  • Just 6.6%