Creating your first Extendable Contract

This page describes a simple example to using the Extendable framework to create your first contract.

Extendable contracts are made extendable through the inheritance of a single contract Extendable.sol.

The basics

First install the framework to make it available in your development environment:

npm install @violetprotocol/extendable

or

yarn add @violetprotocol/extendable

Then import it for use in your contract:

import "@violetprotocol/extendable/extendable/Extendable.sol";

contract YourContract is Extendable {
    constructor(address extendLogic) Extendable(extendLogic) {}
}

There you have it, a minimal implementation of an Extendable contract! Your contract is a very barebones contract that only has functionality to be able to be extended and now you are ready to add more functionality.

Bear in mind that this minimal implementation does assume that an instance of ExtendLogic and PermissionLogic extensions are deployed on the network you intend to deploy this contract as you'll need to pass in their contract addresses to the constructor of your contract.

Developing further

You may want to include some extra functionality to your base contract upon deployment. This is done by first deploying those functionalities as standalone extensions separately and then including these as initial extensions in the constructor:

contract YourContract is Extendable {
    constructor(address yourLogic, address extendLogic) Extendable(extendLogic) {
        (bool extendSuccess, ) = extendLogic.delegatecall(abi.encodeWithSignature("extend(address)", yourLogic));
        require(extendSuccess, "failed to extend with yourLogic");
    }
}

We include a low-level call to the ExtendLogic extension to extend your contract with your additional extension upon construction in order to include this functionality by default. This is identical to deploying your contract first and then calling extend() with your additional extension.

In the next section we will delve into creating your own Extensions.

Last updated