Working with Contract Custom Types
Use directly your custom contract types inside a Zephyr program.
Last updated
Use directly your custom contract types inside a Zephyr program.
Last updated
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:
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),
}
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.