Class: OpenEditionERC721

Inherits:
ERC721
  • Object
show all
Defined in:
lib/rubysol/contracts/open_edition_erc721.rb

Instance Method Summary collapse

Methods inherited from ERC721

#_burn, #_exists, #_mint, #approve, #balanceOf, #ownerOf, #setApprovalForAll, #transferFrom

Instance Method Details

#constructor(name:, symbol:, contentURI:, maxPerAddress:, description:, mintStart:, mintEnd:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubysol/contracts/open_edition_erc721.rb', line 11

def constructor(
  name:,
  symbol:,
  contentURI:,
  maxPerAddress:,
  description:,
  mintStart:,
  mintEnd: )
  super(name: name, symbol: symbol)
  
  @maxPerAddress = maxPerAddress
  @description = description
  @contentURI = contentURI
  @mintStart = mintStart
  @mintEnd = mintEnd
end

#mint(amount:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubysol/contracts/open_edition_erc721.rb', line 29

def mint( amount: )
  assert(amount > 0, 'Amount must be positive')
  assert(amount + @_balanceOf[msg.sender] <= @maxPerAddress, 'Exceeded mint limit')
  assert(block.timestamp >= @mintStart, 'Minting has not started')
  assert(block.timestamp < @mintEnd, 'Minting has ended')
  
  amount.times do |id|
    _mint(to: msg.sender, id: @totalSupply + id)
  end
  
  @totalSupply += amount
end

#tokenURI(id:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubysol/contracts/open_edition_erc721.rb', line 43

def tokenURI( id: ) 
  assert(_exists(id: id), 'ERC721Metadata: URI query for nonexistent token')

  json_data = {
    name: "#{@name} ##{string(id)}",
    description: @description,
    image: @contentURI,
  }.to_json
  
  "data:application/json,#{json_data}"
end