Unlock
Search…
Smart Contracts
The Unlock Protocol, at it's core, is enabled by 2 primary Ethereum smart contracts, deployed on all networks supported by Unlock: the Unlock and the PublicLock contracts. We have a few more contracts, such as the governance token contract and the actual governance contract but they are not actually required by the core protocol.

Unlock

This is our "factory" contract (Unlock.sol) and has several roles.
  • Deploying Locks: locks are deployed through the Unlock smart contract. This is important because the Locks will actually invoke the Unlock smart contract when keys are sold and the Unlock smart contract will check that the invoking lock has been deployed through it.
  • Keeping Track of the Unlock Discount Tokens. Unlock Discount Tokens are ERC20 tokens which implement the Unlock network referral program to let users of the protocol govern it. The Discount Tokens are granted when keys (NFT) are purchased.
You should not need to deploy an Unlock contract yourself. Here are the addresses of contracts deployed on respective networks and you can call them directly using the block explorer.

Production networks:

Test networks:

Please, refer to the Unlock contract documentation for more details.

Lock Contract

This is the contract (PublicLock.sol) which users can configure and deploy to restrict access to resources, such as a blog, a subset of software features, or an event.
  • Each lock contract is an ERC-721 compliant contract capable of creating and managing NFT's (non-fungible tokens we call "Keys"), as well as restricting access based on the user's possession (or lack of) one of these keys.
  • Keys for one lock are valid only for the lock which created them.
  • A given user may own only 1 key (NFT) at a time.
There as well you can call the Lock contracts directly using the block explorers.
Please, refer to the Lock contract documentation for more details.

Upgradeability

We're making use of upgradeable contracts via openzeppelin 's approach which leverages proxy contracts. What does this mean for users? First, when interacting with the Unlock contract ( via the dashboard, etherscan, from another smart-contract, or from a new UI you build, you will always be interacting with the most recent version of the contract. Under the hood, the contract you interact with is actually a proxy contract, so its address never changes. When we upgrade to a new version of Unlock, the proxy is also updated to delegate all calls to the new version of Unlock.

What about Locks?

Good question. Until version 10, Deployed locks are immutable. That is, while they can be re-configured, disabled or destroyed by their owner, they will otherwise remain unchanged on the ethereum network for as long as it persists. Nobody else can modify a lock you deployed but you, unless you choose to allow this. After an upgrade of Unlock, all new locks deployed moving forward will be of the new version, and may support new features and/or improved usability.
Starting with version 10, we are introducing upgradable locks. These locks are still deployed and owned by their creator, but they can later be upgraded to support new features introduced by the protocol, by their lock mnanagers only. The upgrades are optional and can only be triggered by the lock managers themselves.

Npm Modules

Each version of the contracts is available via the @unlock-protocol/contracts module. Among other things, this module includes the compiled artifacts for both Unlock.sol and PublicLock.sol, as well as the interfaces for our contracts, a change log and the commit hash for this version. This allows us (or anyone) to support multiple versions when building on Unlock!

How to use

1
yarn add @unlock-protocol/contracts
Copied!
With javascript
1
// get latest
2
import unlock from '@unlock-protocol/contracts/abis/Unlock'
3
4
// get previous versions
5
import unlock from '@unlock-protocol/contracts/abis/UnlockV0'
6
import { UnlockV0 } from '@unlock-protocol/contracts'
Copied!
With Solidity
1
import "@unlock-protocol/contracts/dist/Unlock/UnlockV0.sol";
Copied!

Standards

Other standards which Unlock adheres to are:
  • erc-1167 - Minimal Proxy Contract
  • erc-1820 - Pseudo-introspection Registry Contract
  • erc-165 - Standard Interface Detection
  • erc-712 - Ethereum typed structured data hashing and signing (in progress)
  • erc-20 - Token Standard (in progress)
Last modified 1mo ago