forked from bitgord/mlg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol-wallet.html
More file actions
319 lines (302 loc) · 20.1 KB
/
Copy pathsol-wallet.html
File metadata and controls
319 lines (302 loc) · 20.1 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->
<!--[if gt IE 8]><!-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="description" content="A tutorial that goes over how to create a wallet and with a balance and transfer ...">
<meta name="author" content="MLG Blockchain">
<link rel="shortcut icon" href="img/favicon.png">
<title>How to Setup a Wallet Smart Contract with Solidity</title>
<!-- Bootstrap Core CSS -->
<link href="assets/css/bootstrap/bootstrap.min.css" rel="stylesheet" type="text/css">
<!-- Retina.js - Load first for faster HQ mobile images. -->
<script src="assets/js/plugins/retina/retina.min.js"></script>
<!-- Font Awesome -->
<link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- Default Fonts -->
<link href='http://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Raleway:400,100,200,300,600,500,700,800,900' rel='stylesheet' type='text/css'>
<!-- Modern Style Fonts (Include these is you are using body.modern!) -->
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Cardo:400,400italic,700' rel='stylesheet' type='text/css'>
<!-- Vintage Style Fonts (Include these if you are using body.vintage!) -->
<link href='http://fonts.googleapis.com/css?family=Sanchez:400italic,400' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Cardo:400,400italic,700' rel='stylesheet' type='text/css'>
<!-- Plugin CSS -->
<link href="assets/css/plugins/owl-carousel/owl.carousel.css" rel="stylesheet" type="text/css">
<link href="assets/css/plugins/owl-carousel/owl.theme.css" rel="stylesheet" type="text/css">
<link href="assets/css/plugins/owl-carousel/owl.transitions.css" rel="stylesheet" type="text/css">
<link href="assets/css/plugins/magnific-popup.css" rel="stylesheet" type="text/css">
<link href="assets/css/plugins/background.css" rel="stylesheet" type="text/css">
<link href="assets/css/plugins/animate.css" rel="stylesheet" type="text/css">
<!-- Vitality Theme CSS -->
<!-- Uncomment the color scheme you want to use. -->
<link href="assets/css/vitality-red.css" rel="stylesheet" type="text/css">
<link href="assets/css/mlg.css" rel="stylesheet" type="text/css">
<!-- <link href="assets/css/vitality-aqua.css" rel="stylesheet" type="text/css"> -->
<!-- <link href="assets/css/vitality-blue.css" rel="stylesheet" type="text/css"> -->
<!-- <link href="assets/css/vitality-green.css" rel="stylesheet" type="text/css"> -->
<!-- <link href="assets/css/vitality-orange.css" rel="stylesheet" type="text/css"> -->
<!-- <link href="assets/css/vitality-pink.css" rel="stylesheet" type="text/css"> -->
<!-- <link href="assets/css/vitality-purple.css" rel="stylesheet" type="text/css"> -->
<!-- <link href="assets/css/vitality-tan.css" rel="stylesheet" type="text/css"> -->
<!-- <link href="assets/css/vitality-turquoise.css" rel="stylesheet" type="text/css"> -->
<!-- <link href="assets/css/vitality-yellow.css" rel="stylesheet" type="text/css"> -->
<!-- IE8 support for HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body id="page-top">
<!-- Start: Header Area
================================-->
<header class="header-background header header-2" id="header" data-stellar-background-ratio="0.5">
<div class="fix overlay-color">
<!-- Start: Navbar Area -->
<div class="header-navbar" id="header-navbar">
<!-- Navbar Option -->
<nav class="navbar navbar-inverse navbar-expanded" id="myNavbar" style="padding:10px 0px;">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- TEMPLATE LOGO -->
<a class="navbar-brand" href="index.html"><span><img src="assets/img/logo.png" alt="MLG Blockchain Consulting" class="img-responsive" style="width:100px"></span></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right" id="navbar-nav-2">
<li class="section-selector-2"><a class="btn page-scroll" href="index.html">Home</a></li>
<li class="section-selector-2"><a class="btn page-scroll" href="index.html#about">About</a></li>
<li class="section-selector-2"><a class="btn page-scroll" href="index.html#process">Services</a></li>
<li class="section-selector-2"><a class="btn page-scroll" href="index.html#clients">Clients</a></li>
<li class="section-selector-2"><a class="btn page-scroll" href="blog.html">Blog</a></li>
<li class="section-selector-2"><a class="btn page-scroll" href="index.html#contact">Contact</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
</div>
<!-- End: Navbar Area -->
<!-- Begin Content -->
<section class="post-content">
<div class="container">
<div class="row">
<br><br><br>
<!-- Begin page content -->
<div class="col-xs-12 col-md-9 col-md-push-3">
<div class="content-box">
<p class="blog-date"><span>8</span><br>Jan<br>2017</p>
<img src="assets/img/sol-wallet.jpg" alt="How to Setup a Wallet Smart Contract With Solidity">
</div>
<div class="post-info">
<span>Michael Gord | ethereum, blockchain, solidity, smart contracts, nodejs, blockchain development</span>
</div>
<h2 class="section-title">How to Setup a Wallet Smart Contract With Solidity</h2>
<div class="divider-light"></div>
<div class="page-content">
<p>Below is example solidity code to create your own smart contract. Refer to the <a href="intro-sol-contracts.html">introduction to Solidity</a> tutorial if you need help deploying and interacting with this.</p>
<code>
contract SimpleWallet {<br />
<br />
// Address is the owner<br />
address owner;<br />
<br />
struct WithdrawlStruct {<br />
address to;<br />
uint amount;<br />
}<br />
<br />
// create an object for senders
struct Senders {<br />
bool allowed;<br />
uint amount_sends;<br />
mapping(uint => WithdrawlStruct) withdrawls;<br />
}<br />
<br />
// mapping to determine if sender is allowed to send funds<br />
mapping(address => Senders) isAllowedToSendFundsMapping;<br />
<br />
// event for deposit and for withdraw<br />
event Deposit(address _sender, uint amount);<br />
event Withdraw(address _sender, uint amount, address _beneficiary);<br />
<br />
// set the owner as soon as the wallet is created<br />
function SimpleWallet() {<br />
owner = msg.sender;<br />
}<br />
<br />
// this anonymous function is called when the contract receives funds from an address that is allowed to send funds<br />
// the msg.sender needs to be the owner and allowed to send funds to deposit them<br />
// we also emit an event called deposit and declare the msg sender and the value<br />
function() {<br />
if(isAllowedToSend(msg.sender)) {<br />
Deposit(msg.sender, msg.value);<br />
} else {<br />
throw;<br />
}<br />
}<br />
<br />
// Someone that is allowed to send funds is allowed to send<br />
// in this case if it is the owner or the boolean mapping is true<br />
// their balance must be higher than the event<br />
// if it goes through we emit a withdraw event and return the balance<br />
<br />
function sendFunds(uint amount, address receiver) returns (uint) {<br />
if(isAllowedToSend(msg.sender)) {<br />
if(this.balance >= amount) {<br />
if(!receiver.send(amount)) {<br />
throw;<br />
}<br />
Withdraw(msg.sender, amount, receiver);<br />
<br />
// log each withdrawl, receiver, amount<br />
isAllowedToSendFundsMapping[msg.sender].amount_sends++;<br />
isAllowedToSendFundsMapping[msg.sender].withdrawls[<br />isAllowedToSendFundsMapping[msg.sender].amount_sends].to = receiver;<br />
isAllowedToSendFundsMapping[msg.sender].withdrawls[<br />isAllowedToSendFundsMapping[msg.sender].amount_sends].amount = amount;<br />
return this.balance;<br />
}<br />
}<br />
}<br />
<br />
// Allowed to send funds when the boolean mapping is set to true<br />
function allowAddressToSendMoney(address _address) {<br />
if(msg.sender == owner) {<br />
isAllowedToSendFundsMapping[_address].allowed = true;<br />
}<br />
}<br />
<br />
// Not allowed to send funds when the boolean mapping is set to false<br />
function disallowAddressToSendMoney(address _address) {<br />
if(msg.sender == owner) {<br />
isAllowedToSendFundsMapping[_address].allowed = false;<br />
}<br />
}<br />
<br />
// Check function which returns the boolean value<br />
function isAllowedToSend(address _address) constant returns (bool) {<br />
return isAllowedToSendFundsMapping[_address].allowed || _address == owner;<br />
}<br />
<br />
// check to make sure the msg.sender is the owner or it will suicide the contract and return funds to the owner<br />
function killWallet() {<br />
if(msg.sender == owner) {<br />
suicide(owner);<br />
}<br />
}<br />
}<br />
</code>
<br />
<p>
For more information on Solidity, go to the <a href="https://solidity.readthedocs.io/en/develop/">Solidity Developer documents</a>.
</p>
</br>
<p>
<a href="index.html">MLG Blockchain</a> is a blockchain development and consulting firm based in Toronto that is focused on building next generation applications using blockchain and smart contract technology. For more blockchain development tutorials like these go to our blog <a href="blog.html">MLG Blockchain Blog</a>.
</p>
</div> <!-- End row -->
</div> <!-- End page content -->
<!-- Begin Sidebar -->
<div class="col-xs-12 col-md-3 col-md-pull-9">
<aside class="sidebar-nav">
<h3 class="sidebar-heading">Latest Posts</h3>
<ul>
<li><a href="setup-bitcoind.html" target="_blank">How to Connect to the Bitcoin Blockchain with Bitcoind</a></li>
<li><a href="eris-chain.html" target="_blank">How to Setup a Private Blockchain with Eris</a></li>
<li><a href="sol-wallet.html" target="_blank">How to Setup a Wallet Smart Contract with Solidity</a></li>
<li><a href="ethereum-private-network.html" target="_blank">Use Go-Ethereum to Setup your own Private Ethereum Blockchain</a></li>
<li><a href="intro-sol-contracts.html" target="_blank">Get started with solidity and ethereum smart contracts</a></li>
<li><a href="bitcoinjs-sign.html" target="_blank">Use Ethereumjs-tx and Web3 to Send an Ether Transaction using your Terminal</a></li>
<li><a href="bitcoinjs-address.html" target="_blank">Use Bitcoinjs to generate a new Bitcoin address and private key</a></li>
</ul>
</aside>
</div> <!-- End Sidebar -->
</div> <!-- End row -->
</div> <!-- End container -->
</section> <!-- End Content section -->
<section class="cta-form" id="contact" style="background-image: url('http://www.downvids.net/video/bestimages/img-obj-plexus-after-effects-762.jpg')">
<div class="container text-center">
<h4 style="color:white">Be the first to hear about the newest advancements in blockchain technology!</h3>
<hr class>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<!-- MailChimp Signup Form -->
<div id="mc_embed_signup">
<!-- Replace the form action in the line below with your MailChimp embed action! For more informatin on how to do this please visit the Docs! -->
<form role="form" action="//startbootstrap.us3.list-manage.com/subscribe/post?u=531af730d8629808bd96cf489&id=afb284632f" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" target="_blank" novalidate>
<div class="input-group input-group-lg">
<input type="email" name="EMAIL" class="form-control" id="mce-EMAIL" placeholder="Email address...">
<span class="input-group-btn">
<button type="submit" name="subscribe" id="mc-embedded-subscribe" class="btn btn-primary">Subscribe!</button>
</span>
</div>
<div id="mce-responses">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div>
</form>
</div>
<!-- End MailChimp Signup Form -->
</div>
</div>
</div>
</section>
<footer id="footer" class="footer">
<div class="container text-center">
<div class="row" style="color:black">
<div class="col-md-4 contact-details">
<h4><i class="fa fa-phone"></i> Call</h4>
<p>647-377-3489</p>
</div>
<div class="col-md-4 contact-details">
<h4><i class="fa fa-map-marker"></i> Visit</h4>
<p>Toronto, Canada</p>
</div>
<div class="col-md-4 contact-details">
<h4><i class="fa fa-envelope"></i> Email</h4>
<p style="color:black">hello@mlgblockchain.com</p>
</div>
</div>
<div class="row copyright">
<div class="col-lg-12">
<center><a href="index.html"><img src="assets/img/mlg.png" alt="MLG Blockchain Consulting" class="img-responsive" style="width:100px"></a></center>
<br>
<p class="small" style="color:black">© 2017 MLG Blockchain Consulting</p>
</div>
</div>
</div>
</footer>
<!-- SCRIPTS
========================================-->
<!-- Core Scripts -->
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap/bootstrap.min.js"></script>
<!-- Plugin Scripts -->
<script src="assets/js/plugins/google-analytics.js"></script>
<script src="assets/js/plugins/jquery.easing.min.js"></script>
<script src="assets/js/plugins/classie.js"></script>
<script src="assets/js/plugins/cbpAnimatedHeader.js"></script>
<script src="assets/js/plugins/owl-carousel/owl.carousel.js"></script>
<script src="assets/js/plugins/jquery.magnific-popup/jquery.magnific-popup.min.js"></script>
<script src="assets/js/plugins/background/core.js"></script>
<script src="assets/js/plugins/background/transition.js"></script>
<script src="assets/js/plugins/background/background.js"></script>
<script src="assets/js/plugins/jquery.mixitup.js"></script>
<script src="assets/js/plugins/wow/wow.min.js"></script>
<script src="assets/js/contact_me.js"></script>
<script src="assets/js/plugins/jqBootstrapValidation.js"></script>
<!-- Vitality Theme Scripts -->
<script src="assets/js/vitality.js"></script>
</body>
</html>