You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- rewritten useScQuery, but it keeps backward compatibility, you can still use simple data types like number, string and boolan as the results without ABI, if you need to catch more complex data types, you need to provide the ABI file, check for more info in the README.md file
Nextjs alternative to the [dapp-core](https://github.com/ElrondNetwork/dapp-core).
6
-
Based on [Elven Tools Dapp](https://www.elven.tools/docs/minter-dapp-introduction.html).
6
+
Based on [Elven Tools Dapp](https://www.elven.tools/docs/minter-dapp-introduction.html), (It is developed simultaneously, and at some stages, it will have more core functionality)
7
7
8
8
The Dapp is built using Nextjs and a couple of helpful tools.
9
9
It has straightforward and complete functionality.
@@ -12,8 +12,8 @@ It has straightforward and complete functionality.
12
12
13
13
- it works on Nextjs
14
14
- it uses erdjs 11.* without the dapp-core library.
15
-
-it uses backedside redirections to hide the API endpoint. The only exposed one is `/api/multiversx` and it is used only be the dapp internally
16
-
- it uses the .env file - there is an example in the repo (for all configuration, also for the demo config)
15
+
it uses backed-side redirections to hide the API endpoint. The only exposed one is `/api/multiversx` and it is used only by the dapp internally
16
+
- it uses the .env file - there is an example in the repo (for all configurations, also for the demo config)
17
17
- it uses chakra-ui
18
18
19
19
### How to start it locally:
@@ -25,15 +25,15 @@ It has straightforward and complete functionality.
25
25
5.`npm run dev` -> for development
26
26
6.`npm run build` -> `npm start` for production
27
27
28
-
Check how to deploy very similar dapp using the Netlify services: https://www.elven.tools/docs/dapp-deployment.html
28
+
Check how to deploy a very similar dapp using the Netlify services: https://www.elven.tools/docs/dapp-deployment.html
29
29
30
30
### Howto
31
31
32
32
For simplicity, the template uses the main index page with demo components built using the core building blocks. Below you will find the list of most essential utilities, hooks, and components with examples that are actual code from the template. You can search them in the code to better understand how they work.
33
33
34
34
There are much more hooks and tools, but most of them are already used in the ones listed below.
35
35
36
-
The code samples are not ready to copy and paste. Please search them in the code.
36
+
The code samples are not ready to copy and paste. Please search for them in the code.
The hook uses useSWR under the hood and can be triggered on a component mount or remotely on some action. It has two different states for the pending action. For initial load and on revalidate. It also takes one of three return data types: 'number', 'string', 'boolean'. For now, it assumes that you know what data type will be returned by a smart contract. Later it will get more afvanced functionality.
143
+
The hook uses useSWR under the hood and can be triggered on a component mount or remotely on some action. It has two different states for the pending action. For initial load and on revalidate. It also takes one of three return data types: 'number', 'string', 'boolean'. For now, it assumes that you know what data type will be returned by a smart contract. Later it will get more advanced functionality.
144
144
145
145
```jsx
146
146
const {
@@ -150,16 +150,51 @@ const {
150
150
isValidating, // pending state for each revalidation of the data, for example using the mutate
151
151
error,
152
152
} = useScQuery<number>({
153
-
type:SCQueryType.NUMBER, // can be number, string or boolean
153
+
type:SCQueryType.NUMBER, // can be NUMBER, STRING, BOOLEAN or COMPLEX
args: [],// arguments for the query in hex format, you can use erdjs for that, for example: args: [ new Address('erd1....').hex() ] etc. It will be also simplified in the future.
158
158
},
159
159
autoInit:false, // you can enable or disable the trigger of the query on the component mount
160
+
abiJSON: yourImportedAbiJSONObject // required for SCQueryType.COMPLEX type
160
161
});
161
162
```
162
163
164
+
**Example** with `SCQueryType.COMPLEX`. This type uses `/vm-values/query`, ABI and ResultParser. The ABI JSON contents are required here. You can copy abi.json and import it in the same place you use useScQuery. Put the abi JSON file wherever you like in the codebase. I chose the `config` directory. See the example below:
args: [], // args in hex format, use erdjs for conversion, see above
176
+
},
177
+
autoInit:true,
178
+
abiJSON,
179
+
});
180
+
```
181
+
182
+
The `data` here will be a `TypedOutcomeBundle`. Which is:
183
+
184
+
```typescript
185
+
interfaceTypedOutcomeBundle {
186
+
returnCode:ReturnCode;
187
+
returnMessage:string;
188
+
values:TypedValue[];
189
+
firstValue?:TypedValue;
190
+
secondValue?:TypedValue;
191
+
thirdValue?:TypedValue;
192
+
lastValue?:TypedValue;
193
+
}
194
+
```
195
+
196
+
You can then process the data. For example `data.firstValue.valueOf()` or `data.firstValue.toString()` if applicable. The returned type can be further processed using erdjs.
197
+
163
198
#### useLoggingIn()
164
199
165
200
The hook will provide information about the authentication flow state. It will tell if the user is already logged in or is logging in.
The hook will provide the information about the user's auth data state. The data: loginMethod, expires, loginToken, signature. Login token and signature won't always be there. It depends if you'll use the token. Check [Elven Tools Dapp backend integration article](https://www.elven.tools/docs/dapp-backend-integration.html) for more info.
216
+
The hook will provide information about the user's auth data state. The data: loginMethod, expires, loginToken, signature. Login token and signature won't always be there. It depends if you'll use the token. Check [Elven Tools Dapp backend integration article](https://www.elven.tools/docs/dapp-backend-integration.html) for more info.
The hook provides a convenient way of doing custom API calls unrelated to transactions or smart contract queries. By default it will use MultiversX API endpoint. But it can be any type of API, not only MultiversX API. In that case you would need to pass the `{ baseEndpoint: "https://some-api.com" }` in options
224
+
The hook provides a convenient way of doing custom API calls unrelated to transactions or smart contract queries. By default, it will use MultiversX API endpoint. But it can be any type of API, not only MultiversX API. In that case, you would need to pass the `{ baseEndpoint: "https://some-api.com" }` in options
0 commit comments