Skip to main content

Interface References

This section of the docs is generated automatically from the smart contract interface references.

Using Smart Contract Interfaces

A Solidity contract interface is a list of function definitions without implementation. This allows for a seperation between the interface and the implementation much like Abstract Base Classes in Python or C++.

You can use these interfaces in your own smart contracts to interact with Unlock Protocol smart contracts, however, they cannot be used to instantiate a new class.

npm module

We have packaged the interfaces along with the contracts.

Load it in your project

Add them to your project using yarn

yarn add @unlock-protocol/contracts

or npm

npm i @unlock-protocol/contracts

Examples use cases

Creating Hooks

Let us say for instance you would like people to be able to sell their memberships, however you do not want people to pass these around too often to limit turnover. So you want to let people transfer them but when they do you do not want to charge a fee, but instead want to zero out the duration of time left. This might make sense if you have an exclusive membership, like country club with access to physical space, limited in the number of people.

Interfaces can be used to inject custom logic into a lock by registering an onTransferHook that calls the expireAndRefundFor function.

pragma solidity 0.8.17;
import "@unlock-protocol/contracts/dist/PublicLock/IPublicLockV12.sol";

contract TransferHook {
/** Constructor */
constructor() {}

/** Function called after a transfer has completed */

function onKeyTransfer(
address lockAddress,
uint tokenId,
address operator,
address from,
address to,
uint expirationTimestamp
) external{

/** Expire the key but the refund amount is zero */
IPublicLockV12(msg.sender).expireAndRefundFor(tokenId, 0)



In order for the above hook to work you must ensure you set the contract address as a LockManager using addLockManager since the expireAndRefundFor function call requires the LockManager role.

You can find more examples of hooks like this in the Smart Contracts/Hooks section of the tutorials.

Using them inside other smart contracts

If you want to add subscription service functionality you can use them inside of other smart contracts to check for key ownership to the subscription Lock you have created. You can see an example of how that can be done to add paid functions to your dApps using Unlock in our Smart Contracts/Unlocking Smart Contracts section of the tutorials.