Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple License Expiration Example
pragma solidity ^ 0.4.4;
// *****************************************************************
// Please seek expert guidance and perform a solidity security audit
// before using it in financially important code.
// *****************************************************************
contract ArtLicenseExpiration {
address public artwork; // the artwork -- artist has the public/private key
address public buyer; // the buyer of the piece -- who bought the piece
uint256 expirationDate = 1544590800; // 12/12/2018 @ 12:00pm (UTC)
constructor(address _buyer) public {
// immutible -- you could make this modifiable if
// you were to sell the art to another buyer
buyer = _buyer;
artwork = msg.sender;
function isExpired() public returns(bool) {
require(msg.sender == artwork, "Only the art can call this function.");
// use of "now": "now" does not mean current time.
// Now is an alias for block.timestamp. Block.timestamp can be influenced
// by miners to a certain degree, be careful.
return (now >= expirationDate);
function setExpirationDate() public(uint256 _expirationDate) {
require(msg.sender == artwork, "Only the art can call this function.");
expirationDate = _expirationDate;
function() payable {
// maybe anyone can renew the license? The buyer would still own it
require(msg.sender == buyer, "Only the buyer can call this function.");
// here is where you calculate how much you want to charge for time.
// in this example the artwork is worth 1 Wei = 1 second of time
// this is a VERY expensive piece :)
expirationDate += msg.value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment