Unlock
Search…
Using Unlock in other contracts
Smart contract developers can easily integrate with Unlock Protocol on-chain, allowing them to limit access to certain features or change the behavior of functions based on membership status!
In this tutorial, we will focus on integrating a Lock itself, rather than the Unlock contract.

Paid only features

The lock contract has multiple functions you could use to assess the membership status of a given address. The most obvious one is called balanceOf. It will either return 1 if the address owns a valid membership and 0 otherwise (whether the membership has expired, or the address never had one).
Here is an example on how to easily create a contract that has a "members only" feature:
1
pragma solidity ^0.5.0;
2
3
import 'contracts/interfaces/IPublicLock.sol';
4
5
contract PaidOnlyFeature
6
{
7
IPublicLock public lock;
8
9
constructor(IPublicLock _lockAddress) public
10
{
11
lock = _lockAddress;
12
}
13
14
function paidOnlyFeature() public
15
{
16
require(lock.balanceOf(msg.sender) > 0, 'Purchase a membership first!');
17
// ...and then implement your feature as normal. If needed you could even make that a modifier
18
}
19
20
// You can also have free features of course
21
}
Copied!
Last modified 10d ago
Copy link