9.2 Implement traits

Trait conformance means that a smart contract implements the functions defined in the trait.

To implement the trait, ensure that the contract has a 'multiply' function that takes two 'uint' parameters and returns either '(ok uint)' or '(err uint)'. To implement the trait, ensure that the contract has a 'multiply' function that takes two 'uint' parameters and returns either '(ok uint)' or '(err uint)'. The provided contract satisfies these requirements.

The contract has a divide function that is not present in the multiplier trait. However, this is not an issue as any system searching for contracts that implement multiplier does not require knowledge of other functions that those contracts may implement. Relying on the trait ensures that conforming contracts have a compatible multiply function implementation and nothing more.

Therefore, asserting trait implementations. In the opening paragraph of this chapter, we discussed implicit and explicit conformity. It is recommended to always explicitly assert that your contract implements a trait.

For instance, if the multiplier trait is deployed in a contract called multiplier-trait by the same principal, the impl-trait function is used to assert that the example contract implements the trait.

Last updated