質問編集履歴

2

画像追加しました。

2018/06/29 03:01

投稿

Yeeeee
Yeeeee

スコア18

test CHANGED
File without changes
test CHANGED
@@ -124,6 +124,10 @@
124
124
 
125
125
  を使い、
126
126
 
127
+
128
+
129
+ ![イメージ説明](a8524edf4dd65fcc470e2ba62c6ce33e.png)
130
+
127
131
  ["0xhogehogehogehogehogehogehogehoge", "0xhogehogehogehogehogehogehogehoge", "0xhogehogehogehogehogehogehogehoge"], 100
128
132
 
129
133
  などを入力し、「distributeAirdrop」をクリック
@@ -138,7 +142,7 @@
138
142
 
139
143
  を参考にチャレンジしている状況。
140
144
 
141
-
145
+
142
146
 
143
147
  「infura.io + web3.js + ethereumjs-txで実行する」
144
148
 

1

distributeAirdrop部分のコードを記述しました

2018/06/29 03:01

投稿

Yeeeee
Yeeeee

スコア18

test CHANGED
File without changes
test CHANGED
@@ -13,6 +13,112 @@
13
13
  を参考にしコードを作成
14
14
 
15
15
 
16
+
17
+ ```
18
+
19
+ /**
20
+
21
+ * @dev Function to distribute tokens to the list of addresses by the provided amount
22
+
23
+ */
24
+
25
+ function distributeAirdrop(address[] addresses, uint256 amount) public returns (bool) {
26
+
27
+ require(amount > 0
28
+
29
+ && addresses.length > 0
30
+
31
+ && frozenAccount[msg.sender] == false
32
+
33
+ && now > unlockUnixTime[msg.sender]);
34
+
35
+
36
+
37
+ amount = amount.mul(1e8);
38
+
39
+ uint256 totalAmount = amount.mul(addresses.length);
40
+
41
+ require(balanceOf[msg.sender] >= totalAmount);
42
+
43
+
44
+
45
+ for (uint j = 0; j < addresses.length; j++) {
46
+
47
+ require(addresses[j] != 0x0
48
+
49
+ && frozenAccount[addresses[j]] == false
50
+
51
+ && now > unlockUnixTime[addresses[j]]);
52
+
53
+
54
+
55
+ balanceOf[addresses[j]] = balanceOf[addresses[j]].add(amount);
56
+
57
+ Transfer(msg.sender, addresses[j], amount);
58
+
59
+ }
60
+
61
+ balanceOf[msg.sender] = balanceOf[msg.sender].sub(totalAmount);
62
+
63
+ return true;
64
+
65
+ }
66
+
67
+
68
+
69
+ function distributeAirdrop(address[] addresses, uint[] amounts) public returns (bool) {
70
+
71
+ require(addresses.length > 0
72
+
73
+ && addresses.length == amounts.length
74
+
75
+ && frozenAccount[msg.sender] == false
76
+
77
+ && now > unlockUnixTime[msg.sender]);
78
+
79
+
80
+
81
+ uint256 totalAmount = 0;
82
+
83
+
84
+
85
+ for(uint j = 0; j < addresses.length; j++){
86
+
87
+ require(amounts[j] > 0
88
+
89
+ && addresses[j] != 0x0
90
+
91
+ && frozenAccount[addresses[j]] == false
92
+
93
+ && now > unlockUnixTime[addresses[j]]);
94
+
95
+
96
+
97
+ amounts[j] = amounts[j].mul(1e8);
98
+
99
+ totalAmount = totalAmount.add(amounts[j]);
100
+
101
+ }
102
+
103
+ require(balanceOf[msg.sender] >= totalAmount);
104
+
105
+
106
+
107
+ for (j = 0; j < addresses.length; j++) {
108
+
109
+ balanceOf[addresses[j]] = balanceOf[addresses[j]].add(amounts[j]);
110
+
111
+ Transfer(msg.sender, addresses[j], amounts[j]);
112
+
113
+ }
114
+
115
+ balanceOf[msg.sender] = balanceOf[msg.sender].sub(totalAmount);
116
+
117
+ return true;
118
+
119
+ }
120
+
121
+ ```
16
122
 
17
123
  ・https://remix.ethereum.org/
18
124