|
2 | 2 |
|
3 | 3 | In the upcoming v2 release of the Cartesi Rollups SDK, inputs and outputs will be encoded as Solidity function calldata.
|
4 | 4 | This package aims to show front-end developers how inputs and outputs can be encoded or decoded using [`viem`](https://viem.sh/) and the contract ABIs exported by [`@cartesi/rollups`](https://www.npmjs.com/package/@cartesi/rollups).
|
5 |
| -It also comes with a handy-dandy CLI tool for encoding and decoding of inputs and outputs. |
| 5 | +It also comes with a handy-dandy CLI tool. |
6 | 6 |
|
7 |
| -## Installation |
8 |
| - |
9 |
| -You can install the package with `pnpm` by running: |
10 |
| - |
11 |
| -```sh |
12 |
| -pnpm add -g @guidanoli/cmioc |
13 |
| -``` |
14 |
| - |
15 |
| -## Encoding inputs |
16 |
| - |
17 |
| -### To hex |
18 |
| - |
19 |
| -```sh |
20 |
| -cmioc encode input \ |
21 |
| - --chain-id 1 \ |
22 |
| - --app-contract 0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C \ |
23 |
| - --msg-sender 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \ |
24 |
| - --block-number 42 \ |
25 |
| - --block-timestamp 70000 \ |
26 |
| - --prev-randao 40823578488146031703637781058841789769586951870728503003341100870835983872788 \ |
27 |
| - --index 10 \ |
28 |
| - --payload 0xdeadbeef |
29 |
| -``` |
30 |
| - |
31 |
| -Output: |
32 |
| - |
33 |
| -``` |
34 |
| -0x415bf363000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070ac08179605af2d9e75782b8decdd3c22aa4d0c000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000111705a41539c3688747a1a8c7811b98b0427331ff73aab018eb5c9921993d617f314000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000 |
35 |
| -``` |
36 |
| - |
37 |
| -### To binary |
38 |
| - |
39 |
| -Just add the `--binary` flag. |
40 |
| - |
41 |
| -## Decoding inputs |
42 |
| - |
43 |
| -### From hex |
44 |
| - |
45 |
| -```sh |
46 |
| -cmioc decode input 0x415bf363000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070ac08179605af2d9e75782b8decdd3c22aa4d0c000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000111705a41539c3688747a1a8c7811b98b0427331ff73aab018eb5c9921993d617f314000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000 |
47 |
| -``` |
48 |
| - |
49 |
| -or |
50 |
| - |
51 |
| -```sh |
52 |
| -cat input.txt | cmioc decode input |
53 |
| -``` |
54 |
| - |
55 |
| -### From binary |
56 |
| - |
57 |
| -```sh |
58 |
| -cat input.bin | cmioc decode input --binary |
59 |
| -``` |
60 |
| - |
61 |
| -Output: |
62 |
| - |
63 |
| -```json |
64 |
| -{ |
65 |
| - "chainId": "1", |
66 |
| - "appContract": "0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C", |
67 |
| - "msgSender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", |
68 |
| - "blockNumber": "42", |
69 |
| - "blockTimestamp": "70000", |
70 |
| - "prevRandao": "40823578488146031703637781058841789769586951870728503003341100870835983872788", |
71 |
| - "index": "10", |
72 |
| - "payload": "0xdeadbeef" |
73 |
| -} |
74 |
| -``` |
75 |
| - |
76 |
| -## Encoding outputs |
77 |
| - |
78 |
| -### Notices |
79 |
| - |
80 |
| -#### To hex |
81 |
| - |
82 |
| -```sh |
83 |
| -cmioc encode notice \ |
84 |
| - --payload 0xdeadbeef |
85 |
| -``` |
86 |
| - |
87 |
| -Output: |
88 |
| - |
89 |
| -``` |
90 |
| -0xc258d6e500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000 |
91 |
| -``` |
92 |
| - |
93 |
| -#### To binary |
94 |
| - |
95 |
| -Just add the `--binary` flag. |
96 |
| - |
97 |
| -### Vouchers |
98 |
| - |
99 |
| -#### To hex |
100 |
| - |
101 |
| -```sh |
102 |
| -cmioc encode voucher \ |
103 |
| - --destination 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \ |
104 |
| - --value 1000000000000000000 \ |
105 |
| - --payload 0xfafafa |
106 |
| -``` |
107 |
| - |
108 |
| -Output: |
109 |
| - |
110 |
| -``` |
111 |
| -0x237a816f000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000003fafafa0000000000000000000000000000000000000000000000000000000000 |
112 |
| -``` |
113 |
| - |
114 |
| -#### To binary |
115 |
| - |
116 |
| -Just add the `--binary` flag. |
117 |
| - |
118 |
| -### `DELEGATECALL` vouchers |
119 |
| - |
120 |
| -#### To hex |
121 |
| - |
122 |
| -```sh |
123 |
| -cmioc encode delegatecallvoucher \ |
124 |
| - --destination 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \ |
125 |
| - --payload 0xfafafa |
126 |
| -``` |
127 |
| - |
128 |
| -Output: |
129 |
| - |
130 |
| -``` |
131 |
| -0x10321e8b000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003fafafa0000000000000000000000000000000000000000000000000000000000 |
132 |
| -``` |
133 |
| - |
134 |
| -#### To binary |
135 |
| - |
136 |
| -Just add the `--binary` flag. |
137 |
| - |
138 |
| -## Decoding outputs |
139 |
| - |
140 |
| -### Notices |
141 |
| - |
142 |
| -#### From hex |
143 |
| - |
144 |
| -```sh |
145 |
| -cmioc decode output 0xc258d6e500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000 |
146 |
| -``` |
147 |
| - |
148 |
| -or |
149 |
| - |
150 |
| -```sh |
151 |
| -cat notice.txt | cmioc decode output |
152 |
| -``` |
153 |
| - |
154 |
| -#### From binary |
155 |
| - |
156 |
| -```sh |
157 |
| -cat notice.bin | cmioc decode output --binary |
158 |
| -``` |
159 |
| - |
160 |
| -Output: |
161 |
| - |
162 |
| -```json |
163 |
| -{ |
164 |
| - "type": "notice", |
165 |
| - "payload": "0xdeadbeef" |
166 |
| -} |
167 |
| -``` |
168 |
| - |
169 |
| -### Vouchers |
170 |
| - |
171 |
| -#### From hex |
172 |
| - |
173 |
| -```sh |
174 |
| -cmioc decode output 0x237a816f000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000003fafafa0000000000000000000000000000000000000000000000000000000000 |
175 |
| -``` |
176 |
| - |
177 |
| -or |
178 |
| - |
179 |
| -```sh |
180 |
| -cat voucher.txt | cmioc decode output |
181 |
| -``` |
182 |
| - |
183 |
| -#### From binary |
184 |
| - |
185 |
| -```sh |
186 |
| -cat voucher.bin | cmioc decode output --binary |
187 |
| -``` |
188 |
| - |
189 |
| -Output: |
190 |
| - |
191 |
| -```json |
192 |
| -{ |
193 |
| - "type": "voucher", |
194 |
| - "destination": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", |
195 |
| - "value": "1000000000000000000", |
196 |
| - "payload": "0xfafafa" |
197 |
| -} |
198 |
| -``` |
199 |
| - |
200 |
| -### `DELEGATECALL` vouchers |
201 |
| - |
202 |
| -#### From hex |
203 |
| - |
204 |
| -```sh |
205 |
| -cmioc decode output 0x10321e8b000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003fafafa0000000000000000000000000000000000000000000000000000000000 |
206 |
| -``` |
207 |
| - |
208 |
| -or |
209 |
| - |
210 |
| -```sh |
211 |
| -cat delegatecallvoucher.txt | cmioc decode output |
212 |
| -``` |
213 |
| - |
214 |
| -#### From binary |
215 |
| - |
216 |
| -```sh |
217 |
| -cat delegatecallvoucher.bin | cmioc decode output --binary |
218 |
| -``` |
219 |
| - |
220 |
| -Output: |
221 |
| - |
222 |
| -```json |
223 |
| -{ |
224 |
| - "type": "delegatecallvoucher", |
225 |
| - "destination": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", |
226 |
| - "payload": "0xfafafa" |
227 |
| -} |
228 |
| -``` |
| 7 | +For documentation, please visit **https://cmioc.vercel.app/**. |
0 commit comments