@@ -55,6 +55,18 @@ const block = await unichain.api.getBlockByNumber(blockNumber)
55
55
console .log (' Block data:' , block)
56
56
```
57
57
58
+ #### Try It yourself
59
+ <div class =" u_center " >
60
+ <input id =" blockID " class =" u_input u_full " placeholder =" Input block ID or block hash " ></input >
61
+ <p id =" blockError " style =" color :red " ></p >
62
+ <div >
63
+ <textarea id =" blockRes " style =" visibility : hidden ; width : 100% ;margin-top :5px ;padding :5px " disabled >
64
+ </textarea >
65
+ </div >
66
+ <input type =" button " class =" u_button u_button_primary u_margin_top_10 " onClick =" getBlock ()" value =" Get Block Info " ></input >
67
+ </div >
68
+
69
+
58
70
### Transaction format
59
71
The transaction will have the following structure:
60
72
``` js
@@ -114,9 +126,71 @@ Please note that the transaction and block will be finalized after ⅔ of the wi
114
126
curl -X POST http://{host}/walletsolidity/gettransactionbyid -d '{"value": "transaction_hash"}'
115
127
```
116
128
129
+ #### Try It yourself
130
+ <div class =" u_center " >
131
+ <input id =" txid " class =" u_input u_full " placeholder =" Input transaction ID " ></input >
132
+ <p id =" txError " style =" color :red " ></p >
133
+ <div >
134
+ <textarea id =" txRes " style =" visibility : hidden ; width : 100% ;margin-top :5px ;padding :5px " disabled >
135
+ </textarea >
136
+ </div >
137
+ <input type =" button " class =" u_button u_button_primary u_margin_top_10 " onClick =" getTx ()" value =" Get Transaction Info " ></input >
138
+ </div >
139
+
117
140
### Related resources:
118
141
- [ How to run UniChain node] ( ./getStarted )
119
142
- [ How to use UniChainJS library] ( ./docs/tutorials/tutorial-002 )
120
143
121
144
122
-
145
+ <script type =" text/javascript " >
146
+ function isNumeric (value ) {
147
+ return / ^ -? \d + $ / .test (value);
148
+ }
149
+ function isHex (hexString ) {
150
+ const re = / [0-9A-Fa-f ] {64} / g
151
+ return re .test (hexString)
152
+ }
153
+ function getBlock () {
154
+ const blockId = document .getElementById (" blockID" ).value
155
+ // TODO: validate
156
+ let url = ' https://seed-1.unichain.world/wallet/'
157
+ let data = {}
158
+ console .log (blockId)
159
+ if (isNumeric (blockId)) {
160
+ url += ' getblockbynum'
161
+ data = {num: parseInt (blockId)}
162
+ } else if (isHex (blockId)) { // check hex string
163
+ url += ' getblockbyid'
164
+ data = {value: blockId}
165
+ } else {
166
+ document .getElementById (" blockError" ).innerHTML = ' Invalid block ID or block hash'
167
+ return
168
+ }
169
+ axios .post (url, data).then (res => {
170
+ console .log (res .data )
171
+ document .getElementById (" blockRes" ).innerHTML = JSON .stringify (res .data )
172
+ document .getElementById (" blockRes" ).rows = 10
173
+ document .getElementById (" blockRes" ).style .visibility = ' visible'
174
+ }).catch (err => {
175
+ document .getElementById (" blockError" ).innerHTML = JSON .stringify (err)
176
+ })
177
+ }
178
+ function getTx () {
179
+ const txid = document .getElementById (" txid" ).value
180
+ let url = ' https://seed-1.unichain.world/wallet/gettransactionbyid'
181
+ console .log (txid)
182
+ if (txid .length != 64 || ! isHex (txid)) {
183
+ document .getElementById (" txError" ).innerHTML = ' Invalid transaction hash'
184
+ return
185
+ }
186
+ axios .post (url, {value: txid}).then (res => {
187
+ console .log (res .data )
188
+ document .getElementById (" txRes" ).innerHTML = JSON .stringify (res .data )
189
+ document .getElementById (" txRes" ).rows = 10
190
+ document .getElementById (" txRes" ).style .visibility = ' visible'
191
+ }).catch (err => {
192
+ console .log (err)
193
+ document .getElementById (" txError" ).innerHTML = JSON .stringify (err)
194
+ })
195
+ }
196
+ </script >
0 commit comments