Working with Contract Custom Types

Use directly your custom contract types inside a Zephyr program.

An important feature of Zephyr is that you can import and use in your program custom contract types. This significantly improves the development experience and makes the whole process quicker.

Let's see how this works:

Import the custom type

To use your type in the program's logic you need to define it, as in a contract:

#[derive(Clone)]
#[contracttype]
pub enum PoolFactoryDataKey {
    Contracts(Address),
}

Use the type in your flow

Now you can leverage the type in your program as you prefer. In this example, the entry value was stored in the ledger as a PoolFactoryDataKey::Contracts(Address) and we are making sure that this is effectively the type that wraps address.

for entry in entries {
            if let Ok(entry) = env.try_from_scval(&entry.key) {
                let PoolFactoryDataKey::Contracts(address) = entry;
                pools.push(address)
            }
}

View here the complete example.

Last updated