Odra.toml
As mentioned in the previous article, Odra.toml is a file that contains information about all the contracts
that Odra will build. Let's take a look at the file structure again:
[[contracts]]
fqn = "flipper::Flipper"
The fqn (Fully Qualified Name) is the Rust path to your contract's struct, and it is used by the
building tools to locate and build the contract. In a single-crate project it has two segments:
the module (here flipper, i.e. src/flipper.rs) and the struct (Flipper).
The last segment of the fqn will be used as the name for your contract - the generated wasm file will
be in the above case named Flipper.wasm, matching the struct name exactly, capital letter included.
In a workspace project (cargo odra new -t workspace) the fqn gains a third, leading segment - the
crate name - so it reads <crate>::<module>::<Struct>, for example flipper::flipper::Flipper.
Adding a new contract manually
Besides using the cargo odra generate command, you can add a new contract to be compiled by hand.
To do this, add another [[contracts]] element, name it and make sure that the fqn is set correctly.
For example, if you want to create a new contract called counter, your Odra.toml file should finally
look like this:
[[contracts]]
fqn = "flipper::Flipper"
[[contracts]]
fqn = "counter::Counter"
Contracts from other crates
A contract does not have to live in your project. If the fqn starts with the name of a crate your
project depends on, Odra builds that crate's contract for you. For example, with odra-modules in
your Cargo.toml:
[[contracts]]
fqn = "odra_modules::erc20::Erc20"
[[contracts]]
fqn = "odra_modules::cep18_token::Cep18"
cargo odra build -c Erc20 and cargo odra schema -c Erc20 write wasm/Erc20.wasm and
resources/casper_contract_schemas/erc20_schema.json in the current project, next to the wasm files
and schemas of your own contracts - there is nothing to copy from the other crate's directory.
The contract is then used like any local one: the Erc20HostRef comes from odra_modules::erc20,
and env.deploy in tests or a livenet script finds the wasm by the struct name as usual.
What's next
In the next section, we'll take a closer look at the code that was generated by Odra by default - the famous
Flipper contract.