Skip to main content

Build the app

As usual, we run cubist build from the top-level token bridge app directory. ERC20Bridged is currently configured to run on Polygon and TokenSender on Ethereum, but you can change that easily from the configuration file.

note

The following instructions assume that you have installed Cubist.

What's going on behind the scenes

Cubist generates files in the build directory and the app's Rust src directory.

The build directory

As usual, when we build, we end up with a build directory that contains one directory per target chain:

build
├── ethereum
│   ├── artifacts // Compiled contracts that will run on ethereum
│ │ ├── ...
│   └── contracts // Source files of all original contracts (or ethereum shims)
│ └── ...
└── polygon
├── artifacts // Compiled contracts that will run on polygon
│   ├── ...
└── contracts // Source files of all original contracts (or polygon shims)
└── ...

In build, Cubist saves:

  1. The ABIs and other data produced when compiling the contracts with solc (within each target's artifacts directory)
  2. Original and shim source files (within each target's contracts directory). Cubist copies each contract in your contracts directory and puts them here (or replaces them with their shim, if applicable)
  3. The information that lets the off-chain relayer do its job (in ${ContractName}.bridge.json files).

The polygon and ethreum artifacts directories both contain an ERC20Bridged file and a TokenSender file; that's because both contracts are used cross-chain, so they have shim on the chain that's not their original target. Within the artifacts directory, we also see a number of other directories corresponding to code that we didn't write. For example, in the polygon/artifacts directory, we see directories for ERC20, IERC20, and more. This extra data is generated during compilation because our token bridge contracts require it; for example, ERC20Bridged inherits from ERC20 (which it imports from OpenZepplin via npm).

danger

In general, you should not modify any of the files in the build directory. These files are automatically generated, so your changes may get overwritten.

The src directory

As you probably know by now, when you run cubist build, Cubist also adds files to your Rust src directory; these files allow you to interact with your smart contracts from within Rust.

In this case, the src dir contains the code that allows our Rust dapp to interact with with the TokenSender and ERC20Bridged contracts. After running build, our source directory looks like this:

src
├── main.rs // Our dapp code
├── cubist_gen.rs // Cubist-generated bindings for interacting with both contracts
└── cubist_gen
├── erc20_bridged.rs // Cubist-generated bindings for ERC20Bridged
└── token_sender.rs // Cubist-generated bindings for TokenSender

Your app code will use the bindings that Cubist generates in cubist_gen and cubist_gen.rs; we'll walk through some functions in that file and directory when we run our app in the next step.