Skip to main content

IPublicLockV10

The PublicLock Interface

Methods​

DEFAULT_ADMIN_ROLE​

function DEFAULT_ADMIN_ROLE() external pure returns (bytes32 role)

Returns​

NameTypeDescription
rolebytes32undefined

KEY_GRANTER_ROLE​

function KEY_GRANTER_ROLE() external pure returns (bytes32 role)

Returns​

NameTypeDescription
rolebytes32undefined

LOCK_MANAGER_ROLE​

function LOCK_MANAGER_ROLE() external pure returns (bytes32 role)

Returns​

NameTypeDescription
rolebytes32undefined

addKeyGranter​

function addKeyGranter(address account) external nonpayable

Parameters​

NameTypeDescription
accountaddressundefined

addLockManager​

function addLockManager(address account) external nonpayable

Parameters​

NameTypeDescription
accountaddressundefined

approve​

function approve(address to, uint256 tokenId) external nonpayable

Parameters​

NameTypeDescription
toaddressundefined
tokenIduint256undefined

approveBeneficiary​

function approveBeneficiary(address _spender, uint256 _amount) external nonpayable returns (bool)

An ERC-20 style approval, allowing the spender to transfer funds directly from this lock.

Parameters​

NameTypeDescription
_spenderaddressaddress that can spend tokens belonging to the lock
_amountuint256amount of tokens that can be spent by the spender

Returns​

NameTypeDescription
_0boolundefined

balanceOf​

function balanceOf(address _owner) external view returns (uint256 balance)

Returns the number of NFTs in owner's account.

Parameters​

NameTypeDescription
_owneraddressundefined

Returns​

NameTypeDescription
balanceuint256undefined

beneficiary​

function beneficiary() external view returns (address)

=================================================================== Auto-generated getter functions from public state variables

Returns​

NameTypeDescription
_0addressundefined

burn​

function burn(uint256 _tokenId) external nonpayable

Deactivate an existing keythe key will be expired and ownership records will be destroyed

Parameters​

NameTypeDescription
_tokenIduint256the id of token to burn

cancelAndRefund​

function cancelAndRefund(uint256 _tokenId) external nonpayable

allows the key manager to expire a given tokenId and send a refund to the keyOwner based on the amount of time remaining.

Parameters​

NameTypeDescription
_tokenIduint256The id of the key to cancel.

expirationDuration​

function expirationDuration() external view returns (uint256)

Returns​

NameTypeDescription
_0uint256undefined

expireAndRefundFor​

function expireAndRefundFor(uint256 _tokenId, uint256 _amount) external nonpayable

Invoked by a Lock manager to expire the user's key and perform a refund and cancellation of the keyThrows if called by other than a Lock managerThrows if _keyOwner does not have a valid key

Parameters​

NameTypeDescription
_tokenIduint256The key id we wish to refund to
_amountuint256The amount to refund to the key-owner

extend​

function extend(uint256 _value, uint256 _tokenId, address _referrer, bytes _data) external payable

Extend functionThrows if lock is disabled or key does not exist for _recipient. Throws if _recipient == address(0).

Parameters​

NameTypeDescription
_valueuint256the number of tokens to pay for this purchase >= the current keyPrice - any applicable discount (_value is ignored when using ETH)
_tokenIduint256the id of the key to extend
_referreraddressaddress of the user making the referral
_databytesarbitrary data populated by the front-end which initiated the sale

freeTrialLength​

function freeTrialLength() external view returns (uint256)

Returns​

NameTypeDescription
_0uint256undefined

gasRefundValue​

function gasRefundValue() external view returns (uint256 _gasRefundValue)

_gasRefundValue price in wei or token in smallest price unit

Returns the value/rpice to be refunded to the sender on purchase

Returns​

NameTypeDescription
_gasRefundValueuint256undefined

getApproved​

function getApproved(uint256 _tokenId) external view returns (address operator)

Get the approved address for a single NFT

Throws if _tokenId is not a valid NFT.

Parameters​

NameTypeDescription
_tokenIduint256The NFT to find the approved address for

Returns​

NameTypeDescription
operatoraddressThe approved address for this NFT, or the zero address if there is none

getCancelAndRefundValue​

function getCancelAndRefundValue(address _keyOwner) external view returns (uint256 refund)

Determines how much of a refund a key owner would receive if they issued

Parameters​

NameTypeDescription
_keyOwneraddressThe key owner to get the refund value for. a cancelAndRefund block.timestamp. Note that due to the time required to mine a tx, the actual refund amount will be lower than what the user reads from this call.

Returns​

NameTypeDescription
refunduint256undefined

getHasValidKey​

function getHasValidKey(address _user) external view returns (bool)

Checks if the user has a non-expired key.

Parameters​

NameTypeDescription
_useraddressThe address of the key owner

Returns​

NameTypeDescription
_0boolundefined

getRoleAdmin​

function getRoleAdmin(bytes32 role) external view returns (bytes32)

Innherited from Open Zeppelin AccessControl.sol

Parameters​

NameTypeDescription
rolebytes32undefined

Returns​

NameTypeDescription
_0bytes32undefined

getTransferFee​

function getTransferFee(uint256 _tokenId, uint256 _time) external view returns (uint256)

Determines how much of a fee would need to be paid in order to transfer to another account. This is pro-rated so the fee goes down overtime.

Throws if _tokenId does not have a valid key

Parameters​

NameTypeDescription
_tokenIduint256The id of the key check the transfer fee for.
_timeuint256The amount of time to calculate the fee for.

Returns​

NameTypeDescription
_0uint256The transfer fee in seconds.

grantKeys​

function grantKeys(address[] _recipients, uint256[] _expirationTimestamps, address[] _keyManagers) external nonpayable

Allows a Lock manager to give a collection of users a key with no charge. Each key may be assigned a different expiration date.

Throws if called by other than a Lock manager

Parameters​

NameTypeDescription
_recipientsaddress[]An array of receiving addresses
_expirationTimestampsuint256[]An array of expiration Timestamps for the keys being granted
_keyManagersaddress[]undefined

grantRole​

function grantRole(bytes32 role, address account) external nonpayable

Parameters​

NameTypeDescription
rolebytes32undefined
accountaddressundefined

hasRole​

function hasRole(bytes32 role, address account) external view returns (bool)

Parameters​

NameTypeDescription
rolebytes32undefined
accountaddressundefined

Returns​

NameTypeDescription
_0boolundefined

initialize​

function initialize(address _lockCreator, uint256 _expirationDuration, address _tokenAddress, uint256 _keyPrice, uint256 _maxNumberOfKeys, string _lockName) external nonpayable

Functions

Parameters​

NameTypeDescription
_lockCreatoraddressundefined
_expirationDurationuint256undefined
_tokenAddressaddressundefined
_keyPriceuint256undefined
_maxNumberOfKeysuint256undefined
_lockNamestringundefined

isApprovedForAll​

function isApprovedForAll(address _owner, address _operator) external view returns (bool)

Tells whether an operator is approved by a given keyManager

Parameters​

NameTypeDescription
_owneraddressowner address which you want to query the approval of
_operatoraddressoperator address which you want to query the approval of

Returns​

NameTypeDescription
_0boolbool whether the given operator is approved by the given owner

isKeyGranter​

function isKeyGranter(address account) external view returns (bool)

Parameters​

NameTypeDescription
accountaddressundefined

Returns​

NameTypeDescription
_0boolundefined

isLockManager​

function isLockManager(address account) external view returns (bool)

Parameters​

NameTypeDescription
accountaddressundefined

Returns​

NameTypeDescription
_0boolundefined

isOwner​

function isOwner(address account) external nonpayable returns (bool)

Parameters​

NameTypeDescription
accountaddressundefined

Returns​

NameTypeDescription
_0boolundefined

isValidKey​

function isValidKey(uint256 _tokenId) external view returns (bool)

Check if a certain key is validthis makes use of the onValidKeyHook if it is set

Parameters​

NameTypeDescription
_tokenIduint256the id of the key to check validity

Returns​

NameTypeDescription
_0boolundefined

keyExpirationTimestampFor​

function keyExpirationTimestampFor(uint256 _tokenId) external view returns (uint256 timestamp)

Returns the key's ExpirationTimestamp field for a given owner.Returns 0 if the owner has never owned a key for this lock

Parameters​

NameTypeDescription
_tokenIduint256the id of the key

Returns​

NameTypeDescription
timestampuint256undefined

keyManagerOf​

function keyManagerOf(uint256) external view returns (address)

Parameters​

NameTypeDescription
_0uint256undefined

Returns​

NameTypeDescription
_0addressundefined

keyPrice​

function keyPrice() external view returns (uint256)

Returns​

NameTypeDescription
_0uint256undefined

maxKeysPerAddress​

function maxKeysPerAddress() external view returns (uint256)

Returns​

NameTypeDescription
_0uint256the maximum number of key allowed for a single address

maxNumberOfKeys​

function maxNumberOfKeys() external view returns (uint256)

Returns​

NameTypeDescription
_0uint256undefined

mergeKeys​

function mergeKeys(uint256 _tokenIdFrom, uint256 _tokenIdTo, uint256 _amount) external nonpayable

Merge existing keys

Parameters​

NameTypeDescription
_tokenIdFromuint256the id of the token to substract time from
_tokenIdTouint256the id of the destination token to add time
_amountuint256the amount of time to transfer (in seconds)

migrate​

function migrate(bytes _calldata) external nonpayable

Migrate data from the previous single owner => key mapping to the new data structure w multiple tokens.

when all record schemas are sucessfully upgraded, this function will update the schemaVersion variable to the latest/current lock version

Parameters​

NameTypeDescription
_calldatabytesan ABI-encoded representation of the params (v10: the number of records to migrate as uint)

name​

function name() external view returns (string _name)

A descriptive name for a collection of NFTs in this contract

Returns​

NameTypeDescription
_namestringundefined

numberOfOwners​

function numberOfOwners() external view returns (uint256)

Public function which returns the total number of unique owners (both expired and valid). This may be larger than totalSupply.

Returns​

NameTypeDescription
_0uint256undefined

onKeyCancelHook​

function onKeyCancelHook() external view returns (address)

Returns​

NameTypeDescription
_0addressundefined

onKeyPurchaseHook​

function onKeyPurchaseHook() external view returns (address)

Returns​

NameTypeDescription
_0addressundefined

onTokenURIHook​

function onTokenURIHook() external view returns (string)

Returns​

NameTypeDescription
_0stringundefined

onValidKeyHook​

function onValidKeyHook() external view returns (bool)

Returns​

NameTypeDescription
_0boolundefined

owner​

function owner() external view returns (address)

owner() is provided as an helper to mimick the Ownable contract ABI. The Ownable logic is used by many 3rd party services to determine contract ownership - e.g. who is allowed to edit metadata on Opensea. This logic is NOT used internally by the Unlock Protocol and is made available only as a convenience helper.

Returns​

NameTypeDescription
_0addressundefined

ownerOf​

function ownerOf(uint256 tokenId) external view returns (address _owner)

Returns the owner of the NFT specified by tokenId.

Parameters​

NameTypeDescription
tokenIduint256undefined

Returns​

NameTypeDescription
_owneraddressundefined

publicLockVersion​

function publicLockVersion() external pure returns (uint16)

The version number of the current implementation on this network.

Returns​

NameTypeDescription
_0uint16The current version number.

purchase​

function purchase(uint256[] _values, address[] _recipients, address[] _referrers, address[] _keyManagers, bytes[] _data) external payable

when called for an existing and non-expired key, the _keyManager param will be ignored

Purchase functionSetting _value to keyPrice exactly doubles as a security feature. That way if the lock owner increases the price while my transaction is pending I can't be charged more than I expected (only applicable to ERC-20 when more than keyPrice is approved for spending).

Parameters​

NameTypeDescription
_valuesuint256[]array of tokens amount to pay for this purchase >= the current keyPrice - any applicable discount (_values is ignored when using ETH)
_recipientsaddress[]array of addresses of the recipients of the purchased key
_referrersaddress[]array of addresses of the users making the referral
_keyManagersaddress[]optional array of addresses to grant managing rights to a specific address on creation
_databytes[]array of arbitrary data populated by the front-end which initiated the sale

purchasePriceFor​

function purchasePriceFor(address _recipient, address _referrer, bytes _data) external view returns (uint256)

returns the minimum price paid for a purchase with these params.

this considers any discount from Unlock or the OnKeyPurchase hook.

Parameters​

NameTypeDescription
_recipientaddressundefined
_referreraddressundefined
_databytesundefined

Returns​

NameTypeDescription
_0uint256undefined

refundPenaltyBasisPoints​

function refundPenaltyBasisPoints() external view returns (uint256)

Returns​

NameTypeDescription
_0uint256undefined

renewMembershipFor​

function renewMembershipFor(uint256 _tokenId, address _referrer) external nonpayable

Renew a given tokenonly works for non-free, expiring, ERC20 locks

Parameters​

NameTypeDescription
_tokenIduint256the ID fo the token to renew
_referreraddressthe address of the person to be granted UDT

renounceLockManager​

function renounceLockManager() external nonpayable

renounceRole​

function renounceRole(bytes32 role, address account) external nonpayable

Parameters​

NameTypeDescription
rolebytes32undefined
accountaddressundefined

revokeKeyGranter​

function revokeKeyGranter(address _granter) external nonpayable

Parameters​

NameTypeDescription
_granteraddressundefined

revokeRole​

function revokeRole(bytes32 role, address account) external nonpayable

Parameters​

NameTypeDescription
rolebytes32undefined
accountaddressundefined

safeTransferFrom​

function safeTransferFrom(address from, address to, uint256 tokenId) external nonpayable

Transfers a specific NFT (tokenId) from one account (from) to another (to). Requirements: - from, to cannot be zero. - tokenId must be owned by from. - If the caller is not from, it must be have been allowed to move this NFT by either {approve} or {setApprovalForAll}.

Parameters​

NameTypeDescription
fromaddressundefined
toaddressundefined
tokenIduint256undefined

safeTransferFrom​

function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) external nonpayable

Parameters​

NameTypeDescription
fromaddressundefined
toaddressundefined
tokenIduint256undefined
databytesundefined

schemaVersion​

function schemaVersion() external view returns (uint256)

Returns the version number of the data schema currently used by the lockif this is different from publicLockVersion, then the ability to purchase, grant or extend keys is disabled.

will return 0 if no ;igration has ever been run

Returns​

NameTypeDescription
_0uint256undefined

setApprovalForAll​

function setApprovalForAll(address _operator, bool _approved) external nonpayable

disabled when transfers are disabled

Sets or unsets the approval of a given operator An operator is allowed to transfer all tokens of the sender on their behalf

Parameters​

NameTypeDescription
_operatoraddressoperator address to set the approval
_approvedboolrepresenting the status of the approval to be set

setBaseTokenURI​

function setBaseTokenURI(string _baseTokenURI) external nonpayable

Allows a Lock manager to update the baseTokenURI for this Lock.

Throws if called by other than a Lock manager

Parameters​

NameTypeDescription
_baseTokenURIstringString representing the base of the URI for this lock.

setEventHooks​

function setEventHooks(address _onKeyPurchaseHook, address _onKeyCancelHook, address _onValidKeyHook, address _onTokenURIHook) external nonpayable

Allows a Lock manager to add or remove an event hook

Parameters​

NameTypeDescription
_onKeyPurchaseHookaddressHook called when the purchase function is called
_onKeyCancelHookaddressHook called when the internal _cancelAndRefund function is called
_onValidKeyHookaddressundefined
_onTokenURIHookaddressundefined

setExpirationDuration​

function setExpirationDuration(uint256 _newExpirationDuration) external nonpayable

A function to change the default duration of each key in the lockkeys previously bought are unaffected by this change (i.e. existing keys timestamps are not recalculated/updated)

Parameters​

NameTypeDescription
_newExpirationDurationuint256the new amount of time for each key purchased or type(uint).max for a non-expiring key

setGasRefundValue​

function setGasRefundValue(uint256 _gasRefundValue) external nonpayable

Set the value to be refunded to the sender on purchase

Parameters​

NameTypeDescription
_gasRefundValueuint256price in wei or token in smallest price unit

setKeyManagerOf​

function setKeyManagerOf(uint256 _tokenId, address _keyManager) external nonpayable

Update transfer and cancel rights for a given key

Parameters​

NameTypeDescription
_tokenIduint256The id of the key to assign rights for
_keyManageraddressThe address to assign the rights to for the given key

setMaxKeysPerAddress​

function setMaxKeysPerAddress(uint256 _maxKeysPerAddress) external nonpayable

Set the maximum number of keys a specific address can use

Parameters​

NameTypeDescription
_maxKeysPerAddressuint256the maximum amount of key a user can own

setMaxNumberOfKeys​

function setMaxNumberOfKeys(uint256 _maxNumberOfKeys) external nonpayable

Change the maximum number of keys the lock can edit

Parameters​

NameTypeDescription
_maxNumberOfKeysuint256uint the maximum number of keys

setOwner​

function setOwner(address account) external nonpayable

Parameters​

NameTypeDescription
accountaddressundefined

shareKey​

function shareKey(address _to, uint256 _tokenId, uint256 _timeShared) external nonpayable

Allows the key owner to safely share their key (parent key) by transferring a portion of the remaining time to a new key (child key).

Throws if key is not valid.Throws if _to is the zero addressEmit Transfer event

Parameters​

NameTypeDescription
_toaddressThe recipient of the shared key
_tokenIduint256the key to share
_timeShareduint256The amount of time shared checks if _to is a smart contract (code size > 0). If so, it calls onERC721Received on _to and throws if the return value is not bytes4(keccak256('onERC721Received(address,address,uint,bytes)')).

supportsInterface​

function supportsInterface(bytes4 interfaceId) external view returns (bool)

From ERC165.sol

Parameters​

NameTypeDescription
interfaceIdbytes4undefined

Returns​

NameTypeDescription
_0boolundefined

symbol​

function symbol() external view returns (string)

Gets the token symbol

Returns​

NameTypeDescription
_0stringstring representing the token symbol

tokenAddress​

function tokenAddress() external view returns (address)

Returns​

NameTypeDescription
_0addressundefined

tokenByIndex​

function tokenByIndex(uint256 index) external view returns (uint256)

Parameters​

NameTypeDescription
indexuint256undefined

Returns​

NameTypeDescription
_0uint256undefined

tokenOfOwnerByIndex​

function tokenOfOwnerByIndex(address _owner, uint256 index) external view returns (uint256 tokenId)

Parameters​

NameTypeDescription
_owneraddressundefined
indexuint256undefined

Returns​

NameTypeDescription
tokenIduint256undefined

tokenURI​

function tokenURI(uint256 _tokenId) external view returns (string)

A distinct Uniform Resource Identifier (URI) for a given asset.

Throws if _tokenId is not a valid NFT. URIs are defined in RFC 3986. The URI may point to a JSON file that conforms to the "ERC721 Metadata JSON Schema". https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md

Parameters​

NameTypeDescription
_tokenIduint256The tokenID we're inquiring about

Returns​

NameTypeDescription
_0stringString representing the URI for the requested token

totalSupply​

function totalSupply() external view returns (uint256)

Returns​

NameTypeDescription
_0uint256undefined

transfer​

function transfer(address _to, uint256 _value) external nonpayable returns (bool success)

An ERC-20 style transfer.

The typical use case would be to call this with _value 1, which is on par with calling transferFrom. If the user has more than expirationDuration time remaining this may use the shareKey function to send some but not all of the token.

Parameters​

NameTypeDescription
_toaddressundefined
_valueuint256sends a token with _value * expirationDuration (the amount of time remaining on a standard purchase).

Returns​

NameTypeDescription
successboolundefined

transferFeeBasisPoints​

function transferFeeBasisPoints() external view returns (uint256)

Returns​

NameTypeDescription
_0uint256undefined

transferFrom​

function transferFrom(address from, address to, uint256 tokenId) external nonpayable

Transfers a specific NFT (tokenId) from one account (from) to another (to). Requirements: - If the caller is not from, it must be approved to move this NFT by either {approve} or {setApprovalForAll}.

Parameters​

NameTypeDescription
fromaddressundefined
toaddressundefined
tokenIduint256undefined

unlockProtocol​

function unlockProtocol() external view returns (address)

Returns​

NameTypeDescription
_0addressundefined

updateBeneficiary​

function updateBeneficiary(address _beneficiary) external nonpayable

A function which lets a Lock manager update the beneficiary account, which receives funds on withdrawal.

Throws if called by other than a Lock manager or beneficiaryThrows if _beneficiary is address(0)

Parameters​

NameTypeDescription
_beneficiaryaddressThe new address to set as the beneficiary

updateKeyPricing​

function updateKeyPricing(uint256 _keyPrice, address _tokenAddress) external nonpayable

A function which lets a Lock manager of the lock to change the price for future purchases.

Throws if called by other than a Lock managerThrows if lock has been disabledThrows if _tokenAddress is not a valid token

Parameters​

NameTypeDescription
_keyPriceuint256The new price to set for keys
_tokenAddressaddressThe address of the erc20 token to use for pricing the keys, or 0 to use ETH

updateLockName​

function updateLockName(string _lockName) external nonpayable

Allows a Lock manager to assign a descriptive name for this Lock.

Throws if called by other than a Lock manager

Parameters​

NameTypeDescription
_lockNamestringThe new name for the lock

updateLockSymbol​

function updateLockSymbol(string _lockSymbol) external nonpayable

Allows a Lock manager to assign a Symbol for this Lock.

Throws if called by other than a Lock manager

Parameters​

NameTypeDescription
_lockSymbolstringThe new Symbol for the lock

updateRefundPenalty​

function updateRefundPenalty(uint256 _freeTrialLength, uint256 _refundPenaltyBasisPoints) external nonpayable

Allow a Lock manager to change the refund penalty.

Throws if called by other than a Lock manager

Parameters​

NameTypeDescription
_freeTrialLengthuint256The new duration of free trials for this lock
_refundPenaltyBasisPointsuint256The new refund penaly in basis-points(bps)

updateSchemaVersion​

function updateSchemaVersion() external nonpayable

Set the schema version to the latestonly lock manager call call this

updateTransferFee​

function updateTransferFee(uint256 _transferFeeBasisPoints) external nonpayable

Allow a Lock manager to change the transfer fee.

Throws if called by other than a Lock manager

Parameters​

NameTypeDescription
_transferFeeBasisPointsuint256The new transfer fee in basis-points(bps). Ex: 200 bps = 2%

withdraw​

function withdraw(address _tokenAddress, uint256 _amount) external nonpayable

Called by a lock manager or beneficiary to withdraw all funds from the lock and send them to the beneficiary.Throws if called by other than a lock manager or beneficiary

Parameters​

NameTypeDescription
_tokenAddressaddressspecifies the token address to withdraw or 0 for ETH. This is usually the same as tokenAddress in MixinFunds.
_amountuint256specifies the max amount to withdraw, which may be reduced when considering the available balance. Set to 0 or MAX_UINT to withdraw everything. -- however be wary of draining funds as it breaks the cancelAndRefund and expireAndRefundFor use cases.