Library feature

In the ecosystem, there is the convention to gate the entrypoints of your contract behind a compile-time feature. The feature is conventionally called library.

So instead of using the #[entry_point] macro directly, you should do this:

contract.rs
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
    _deps: DepsMut,
    _env: Env,
    _info: MessageInfo,
    _msg: InstantiateMsg,
) -> StdResult<Response> {
    Ok(Response::new())
}
💡

You can see this in action in the cw-plus contracts (opens in a new tab). Here is an example in the cw4-stake contract (opens in a new tab).

The rationale behind this is that currently using #[entry_point] exports special symbols from the binary, and these symbols must be unique.

That means if you have two instantiate endpoints annotated with #[entry_point] somewhere in your project (that includes all your dependencies!), your contract will fail to compile.

Using this library feature will enable developers to use your contract as a dependency and reuse your code.