This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
RemixExampleContract.cairo
154 lines (120 loc) · 4.55 KB
/
RemixExampleContract.cairo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
######### Remix game day
# Using contract functions to manipulate contract variables
# In this exercice, you need to:
# - Understand the basic syntax of the contract
# - Customize it to mint a specific NFT on address XXX
# - Deploy your contract using the remix plugin
# - Interact with your contract on https://goerli.voyager.online/ in order to mint the desired NFT
## What you'll learn
# - How to read StarkNet contracts
# - How to deploy StarkNet contracts using remix
# - How to interact with a deployed contract on StarkNet
## Want to go further? Of course you do! Pick and chose what you want to learn
# - Learn to read Cairo and interact with contract, no code required! https://github.com/l-henri/starknet-cairo-101
# - Deploy your own ERC20 https://github.com/l-henri/starknet-erc20
# - Deploy your own ERC721 https://github.com/l-henri/starknet-erc721
# - Build a cross layer app https://github.com/l-henri/starknet-messaging-bridge
#########
# General directives and imports
#########
%lang starknet
from starkware.cairo.common.cairo_builtins import HashBuiltin
#########
# Declaring storage vars
#########
# Storage vars are by default not visible through the ABI. They are similar to "private" variables in Solidity
# In Cairo, most numbers are represented as felt. Read more about felts here https://www.cairo-lang.org/docs/hello_cairo/intro.html#field-element
#
@storage_var
func nft_to_mint_address_internal() -> (nft_to_mint_address_internal: felt):
end
@storage_var
func nft_to_mint_recipient_internal() -> (nft_to_mint_recipient_internal: felt):
end
#########
# Declaring getters
#########
# Public variables should be declared explicitly with a getter
#
@view
func nft_to_mint_address{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (nft_to_mint_address: felt):
let (nft_to_mint_address) = nft_to_mint_address_internal.read()
return (nft_to_mint_address)
end
@view
func nft_to_mint_recipient{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (nft_to_mint_recipient: felt):
let (nft_to_mint_recipient) = nft_to_mint_recipient_internal.read()
return (nft_to_mint_recipient)
end
#########
# Declaring events
#########
# Like on Ethereum, events are not part of the state, but can be used to log things
#
@event
func set_nft_recipient(nft_recipient: felt):
end
#########
# Declaring interfaces
#########
# This describe how the current contract can interact with other contracts of type IRemix_game_day_nft
#
@contract_interface
namespace IRemix_game_day_nft:
func mint_from_remix(to: felt) :
end
end
#########
# Constructor
#########
# This function is called when the current contract is first deployed
#
@constructor
func constructor{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}():
# Setting the target ERC721 to mint. Set the correct address here.
nft_to_mint_address_internal.write(49)
return ()
end
#########
# External functions
#########
# These functions can be called by other contracts
#
# This function will call the NFT contract stored in nft_to_mint_address and mint an NFT for nft_to_mint_recipient.
# This is the final function call you'll have to make.
# Before doing that, make sure to customize the contract correctly!
@external
func mint_an_nft_for_me_please{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*,
range_check_ptr}() -> ():
# Reading the target NFT address
let (nft_to_mint_address_local) = nft_to_mint_address_internal.read()
# Reading the recipient of the NFT to mint
let (nft_to_mint_recipient_local) = nft_to_mint_recipient_internal.read()
# Minting the NFT. Sneakaaaaaay
IRemix_game_day_nft.mint_from_remix(contract_address=nft_to_mint_recipient_local, to=nft_to_mint_address_local)
return ()
end
# A simple ping function to check that you deployed indeed this contract
# It won't work as is; you need to make sure it returns "Pong" when it is called
# This function returns a felt though, so make sure you encode "Pong" as a felt
@external
func ping{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*,
range_check_ptr}() -> (response: felt):
return (310939380847)
end
# A function to let you set variable nft_to_mint_recipient_internal.
# You don't have to use it, but it may be useful
@external
func set_recipient_address{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*,
range_check_ptr}(recipient_address: felt ):
nft_to_mint_recipient_internal.write(1234567890)
set_nft_recipient.emit(recipient_address)
return ()
end