To get started with the Solidity SDK, run the following command to create a new project:
Or, install the
contracts package into your existing Solidity project:
Using the Solidity SDK
The Solidity SDK can be used to build new smart contracts end-to-end, or to add functionality to your own, existing smart contract using extensions.
Using Base Contracts
The Solidity SDK includes base contracts that are fully complete smart contracts that can be customized by overriding functions OR by adding extensions.
1. To start, import and inherit the base contract. You can find the list of all available base contracts here.
2. Base contracts expect certain constructor arguments to function as intended. Implement a constructor for your smart contract and pass the appropriate values to a constructor for the base contract.
Extensions are to be used via inheritance - your project's smart contract will inherit from them.
1. To start, import and inherit the extension. You can find the list of all available extensions here.
- Some Extensions are Abstract and so require certain functions to be implemented*.
- Some Extensions are Interfaces and so require all the functions to be implemented*.
*implement = write the logic for the function with a matching function signature (matching name, parameters, visibility and return type)
2. Use the functions provided by the Extension to change the behavior of your smart contract.
Inheritance and Overriding Functions
Inheritance allows you to extend your smart contract's properties to include the parent contract's attributes and properties. The inherited functions from this parent contract can be modified in the child contract via a process known as overriding.
Parent contract: Contract that the inheriting contract is inheriting from.
Child contract: The inheriting contract.
To override a function, to add your own custom logic, simply use the keyword
override when declaring the function, making sure that the function signature matches.
To add the original logic from the parent contract, use the keyword
For example, the
ERC721Base contract has an implementation of the function
mintTo, I could instead override this function to add custom logic
and restrict this function in the
myNFT contract to only allow 1 NFT per wallet: