-
Notifications
You must be signed in to change notification settings - Fork 16
/
06_AbiDynamic.sol
44 lines (36 loc) · 1.16 KB
/
06_AbiDynamic.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
contract AbiDynamic {
function testAbiArray() public pure returns (bytes memory){
uint[] memory a = new uint[](3);
a[0] = 1;
a[1] = 2;
a[2] = 3;
return abi.encode(a);
}
function testAbiString() public pure returns (bytes memory){
string memory b = "WTF";
return abi.encode(b);
}
function testAbiStringStaticArray() public pure returns (bytes memory){
string[2] memory strings = ["WTF", "Academy"];
return abi.encode(strings);
}
function testAbiStringArray() public pure returns (bytes memory){
string[] memory strings = new string[](2);
strings[0] = "WTF";
strings[1] = "Academy";
return abi.encode(strings);
}
struct DynamicStruct { uint a; uint[] b; string c; }
function testAbiDynamicStruct() public pure returns (bytes memory){
uint a = 99;
uint[] memory b = new uint[](3);
b[0] = 1;
b[1] = 2;
b[2] = 3;
string memory c = "WTF";
DynamicStruct memory ds = DynamicStruct(a, b, c);
return abi.encode(ds);
}
}