Class: GenerativeERC721
- Inherits:
-
ERC721
- Object
- Contract
- ERC721
- GenerativeERC721
show all
- Defined in:
- lib/rubysol/contracts/generative_erc721.rb
Instance Method Summary
collapse
Methods inherited from ERC721
#_burn, #_exists, #_mint, #approve, #balanceOf, #ownerOf, #setApprovalForAll, #transferFrom
Instance Method Details
#constructor(name:, symbol:, generativeScript:, maxSupply:, description:, maxPerAddress:) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/rubysol/contracts/generative_erc721.rb', line 11
def constructor(
name:,
symbol:,
generativeScript:,
maxSupply:,
description:,
maxPerAddress: )
super(name: name, symbol: symbol)
@maxSupply = maxSupply
@maxPerAddress = maxPerAddress
@description = description
@generativeScript = generativeScript
end
|
#getHTML(seed) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/rubysol/contracts/generative_erc721.rb', line 64
def getHTML( seed )
%{<!DOCTYPE html>
<html>
<head>
<style>
body,
html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
display: block;
}
#canvas {
position: absolute;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
</body>
<script>
window.SEED = #{string(seed)};
#{@generativeScript}
</script>
</html>}
end
|
#mint(amount) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/rubysol/contracts/generative_erc721.rb', line 27
def mint( amount )
assert(amount > 0, 'Amount must be positive')
assert(amount + @_balanceOf[msg.sender] <= @maxPerAddress, 'Exceeded mint limit')
assert(amount + @totalSupply <= @maxSupply, 'Exceeded max supply')
hash = block.blockhash(block.number).cast(:uint256) % (2 ** 48)
amount.times do |id|
tokenId = @totalSupply + id
seed = hash + tokenId
@tokenIdToSeed[tokenId] = seed
_mint(to: msg.sender, id: tokenId)
end
@totalSupply += amount
end
|
#tokenURI(id) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/rubysol/contracts/generative_erc721.rb', line 47
def tokenURI( id )
assert( _exists(id: id), 'ERC721Metadata: URI query for nonexistent token')
html = getHTML(seed: @tokenIdToSeed[id])
html_as_base_64_data_uri = "data:text/html;base64,#{Base64.strict_encode64(html)}"
json_data = {
name: "#{@name} ##{string(id)}",
description: @description,
animation_url: html_as_base_64_data_uri,
}.to_json
"data:application/json,#{json_data}"
end
|