-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathweb3-eth-abi.rst
506 lines (393 loc) · 16.4 KB
/
web3-eth-abi.rst
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
.. _eth-abi:
=========
web3.eth.abi
=========
``web3.eth.abi`` 를 사용하면 EVM (Ethereum Virtual Machine)에 대한 함수 호출을 위해 매개 변수를 ABI (Application Binary Interface)로 디코딩 및 인코딩 할 수 있습니다.
------------------------------------------------------------------------------
encodeFunctionSignature
=====================
.. code-block:: javascript
web3.eth.abi.encodeFunctionSignature(functionName);
함수 이름과 함수 타입의 첫 4 바이트를 sha3를 통해 ABI 서명(ABI Signiture)로 인코딩합니다.
----------
인자(Parameters)
----------
1. ``functionName`` - ``String|Object``: 인코딩 할 함수의 이름입니다
or the :ref:`JSON interface <glossary-json-interface>` object of the function. If string it has to be in the form ``function(type,type,...)``, e.g: ``myFunction(uint256,uint32[],bytes10,bytes)``
-------
반환값(Return)
-------
``String`` - 함수의 ABI 서명값
-------
예제(Example)
-------
.. code-block:: javascript
// From a JSON interface object
web3.eth.abi.encodeFunctionSignature({
name: 'myMethod',
type: 'function',
inputs: [{
type: 'uint256',
name: 'myNumber'
},{
type: 'string',
name: 'myString'
}]
})
> 0x24ee0097
// Or string
web3.eth.abi.encodeFunctionSignature('myMethod(uint256,string)')
> '0x24ee0097'
------------------------------------------------------------------------------
encodeEventSignature
=====================
.. code-block:: javascript
web3.eth.abi.encodeEventSignature(eventName);
Encodes the event name to its ABI signature, which are the sha3 hash of the event name including input types.
----------
인자(Parameters)
----------
1. ``eventName`` - ``String|Object``: The event name to encode.
or the :ref:`JSON interface <glossary-json-interface>` object of the event. If string it has to be in the form ``event(type,type,...)``, e.g: ``myEvent(uint256,uint32[],bytes10,bytes)``
-------
반환값
-------
``String`` - 이벤트의 ABI 서명.
-------
예제
-------
.. code-block:: javascript
web3.eth.abi.encodeEventSignature('myEvent(uint256,bytes32)')
> 0xf2eeb729e636a8cb783be044acf6b7b1e2c5863735b60d6daae84c366ee87d97
// json 인터페이스 오브젝트에서
web3.eth.abi.encodeEventSignature({
name: 'myEvent',
type: 'event',
inputs: [{
type: 'uint256',
name: 'myNumber'
},{
type: 'bytes32',
name: 'myBytes'
}]
})
> 0xf2eeb729e636a8cb783be044acf6b7b1e2c5863735b60d6daae84c366ee87d97
------------------------------------------------------------------------------
encodeParameter
=====================
.. code-block:: javascript
web3.eth.abi.encodeParameter(type, parameter);
유형에 따라 매개 변수를 ABI 표현으로 인코딩합니다.
----------
인자(Parameters)
----------
1. ``type`` - ``String|Object``: 매개 변수의 유형은 유형 목록은`solidity 문서 <http://solidity.readthedocs.io/en/develop/types.html>`_ 를 참조하십시오.
2. ``parameter`` - ``Mixed``: 인코딩 할 실제 매개 변수입니다.
-------
반환값
-------
``String`` - ABI 인코딩된 매개 변수입니다.
-------
예제
-------
.. code-block:: javascript
web3.eth.abi.encodeParameter('uint256', '2345675643');
> "0x000000000000000000000000000000000000000000000000000000008bd02b7b"
web3.eth.abi.encodeParameter('uint256', '2345675643');
> "0x000000000000000000000000000000000000000000000000000000008bd02b7b"
web3.eth.abi.encodeParameter('bytes32', '0xdf3234');
> "0xdf32340000000000000000000000000000000000000000000000000000000000"
web3.eth.abi.encodeParameter('bytes', '0xdf3234');
> "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003df32340000000000000000000000000000000000000000000000000000000000"
web3.eth.abi.encodeParameter('bytes32[]', ['0xdf3234', '0xfdfd']);
> "00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002df32340000000000000000000000000000000000000000000000000000000000fdfd000000000000000000000000000000000000000000000000000000000000"
web3.eth.abi.encodeParameter(
{
"ParentStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256',
"childStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256'
}
}
},
{
"propertyOne": 42,
"propertyTwo": 56,
"childStruct": {
"propertyOne": 45,
"propertyTwo": 78
}
}
);
> "0x000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e"
------------------------------------------------------------------------------
encodeParameters
=====================
.. code-block:: javascript
web3.eth.abi.encodeParameters(typesArray, parameters);
:ref:`JSON interface <glossary-json-interface>` 오브젝트를 기반으로 함수 매개 변수를 인코딩합니다.
----------
인자(Parameters)
----------
1. ``typesArray`` - ``Array<String|Object>|Object``: An array with types or a :ref:`JSON interface <glossary-json-interface>` of a function. See the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
2. ``parameters`` - ``Array``: 인코딩 할 매개 변수입니다.
-------
반환값
-------
``String`` - ABI 인코딩 된 매개 변수.
-------
예제
-------
.. code-block:: javascript
web3.eth.abi.encodeParameters(['uint256','string'], ['2345675643', 'Hello!%']);
> "0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000"
web3.eth.abi.encodeParameters(['uint8[]','bytes32'], [['34','434'], '0x324567fff']);
> "0x0
web3.eth.abi.encodeParameters(
[
'uint8[]',
{
"ParentStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256',
"ChildStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256'
}
}
}
],
[
['34','434'],
{
"propertyOne": '42',
"propertyTwo": '56',
"ChildStruct": {
"propertyOne": '45',
"propertyTwo": '78'
}
}
]
);
> "0x00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000018"
------------------------------------------------------------------------------
encodeFunctionCall
=====================
.. code-block:: javascript
web3.eth.abi.encodeFunctionCall(jsonInterface, parameters);
:ref:`JSON interface <glossary-json-interface>` 오브젝트 와 주어진 매개 변수를 사용하여 함수 호출을 인코딩합니다.
----------
인자(Parameters)
----------
1. ``jsonInterface`` - ``Object``: The :ref:`JSON interface <glossary-json-interface>` object of a function.
2. ``parameters`` - ``Array``: 인코딩 할 매개 변수입니다.
-------
반환값
-------
``String`` - ABI 인코딩된 함수를 호출합니다. 이는 함수의 서명과 인자를 뜻합니다.
[TODO] => The ABI encoded function call. Means function signature + parameters.
-------
예제
-------
.. code-block:: javascript
web3.eth.abi.encodeFunctionCall({
name: 'myMethod',
type: 'function',
inputs: [{
type: 'uint256',
name: 'myNumber'
},{
type: 'string',
name: 'myString'
}]
}, ['2345675643', 'Hello!%']);
> "0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000"
------------------------------------------------------------------------------
decodeParameter
=====================
.. code-block:: javascript
web3.eth.abi.decodeParameter(type, hexString);
ABI 인코딩 매개 변수를 JavaScript에서 사용 가능한 타입으로 디코딩합니다.
----------
인자(Parameters)
----------
1. ``type`` - ``String|Object``: The type of the parameter, see the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
2. ``hexString`` - ``String``: 디코딩 할 ABI 바이트 코드입니다.
-------
반환값
-------
``Mixed`` - 디코딩 된 매개 변수.
-------
예제
-------
.. code-block:: javascript
web3.eth.abi.decodeParameter('uint256', '0x0000000000000000000000000000000000000000000000000000000000000010');
> "16"
web3.eth.abi.decodeParameter('string', '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000');
> "Hello!%!"
web3.eth.abi.decodeParameter('string', '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000');
> "Hello!%!"
web3.eth.abi.decodeParameter(
{
"ParentStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256',
"childStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256'
}
}
},
, '0x000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e');
> {
'0': {
'0': '42',
'1': '56',
'2': {
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'childStruct': {
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'propertyOne': '42',
'propertyTwo': '56'
},
'ParentStruct': {
'0': '42',
'1': '56',
'2': {
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'childStruct': {
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'propertyOne': '42',
'propertyTwo': '56'
}
}
------------------------------------------------------------------------------
decodeParameters
=====================
.. code-block:: javascript
web3.eth.abi.decodeParameters(typesArray, hexString);
ABI 인코딩 매개 변수를 JavaScript에서 사용 가능한 타입으로 디코딩합니다.
----------
인자(Parameters)
----------
1. ``typesArray`` - ``Array<String|Object>|Object``: An array with types or a :ref:`JSON interface <glossary-json-interface>` outputs array. See the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
2. ``hexString`` - ``String``: 디코딩 할 ABI 바이트 코드입니다.
-------
반환값
-------
``Object`` - 디코딩 된 매개 변수를 포함하는 결과 오브젝트입니다.
-------
예제
-------
.. code-block:: javascript
web3.eth.abi.decodeParameters(['string', 'uint256'], '0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000ea000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000');
> Result { '0': 'Hello!%!', '1': '234' }
web3.eth.abi.decodeParameters([{
type: 'string',
name: 'myString'
},{
type: 'uint256',
name: 'myNumber'
}], '0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000ea000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000');
> Result {
'0': 'Hello!%!',
'1': '234',
myString: 'Hello!%!',
myNumber: '234'
}
web3.eth.abi.decodeParameters([
'uint8[]',
{
"ParentStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256',
"childStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256'
}
}
}
], '0x00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000018');
> Result {
'0': ['42', '24'],
'1': {
'0': '42',
'1': '56',
'2':
{
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'childStruct':
{
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'propertyOne': '42',
'propertyTwo': '56'
}
}
------------------------------------------------------------------------------
decodeLog
=====================
.. code-block:: javascript
web3.eth.abi.decodeLog(inputs, hexString, topics);
ABI 인코딩 된 로그 데이터 및 인덱싱 된 토픽 데이터를 디코딩합니다.
----------
인자(Parameters)
----------
1. ``inputs`` - ``Object``: A :ref:`JSON interface <glossary-json-interface>` inputs array. See the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
2. ``hexString`` - ``String``: The ABI byte code in the ``data`` field of a log.
3. ``topics`` - ``Array``: An array with the index parameter topics of the log, without the topic[0] if its a non-anonymous event, otherwise with topic[0].
-------
반환값
-------
``Object`` - 디코딩 된 매개 변수를 포함하는 결과 오브젝트 입니다.
-------
예제
-------
.. code-block:: javascript
web3.eth.abi.decodeLog([{
type: 'string',
name: 'myString'
},{
type: 'uint256',
name: 'myNumber',
indexed: true
},{
type: 'uint8',
name: 'mySmallNumber',
indexed: true
}],
'0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000748656c6c6f252100000000000000000000000000000000000000000000000000',
['0x000000000000000000000000000000000000000000000000000000000000f310', '0x0000000000000000000000000000000000000000000000000000000000000010']);
> Result {
'0': 'Hello%!',
'1': '62224',
'2': '16',
myString: 'Hello%!',
myNumber: '62224',
mySmallNumber: '16'
}