@@ -109,33 +109,37 @@ The hook provides all that is required for triggering transactions. useTransacti
109
109
``` jsx
110
110
const { pending , triggerTx , transaction , txResult , error } = useTransaction ({ cb });
111
111
112
- const handleSendTx = useCallback ( () => {
112
+ const handleSendTx = () => {
113
113
const demoMessage = ' Transaction demo!' ;
114
114
triggerTx ({
115
115
address: process .env .NEXT_PUBLIC_EGLD_TRANSFER_ADDRESS ,
116
116
gasLimit: 50000 + 1500 * demoMessage .length ,
117
117
data: new TransactionPayload (demoMessage),
118
118
value: process .env .NEXT_PUBLIC_EGLD_TRANSFER_AMOUNT ,
119
119
});
120
- }, [triggerTx]) ;
120
+ };
121
121
```
122
122
123
- #### useScTransaction()
124
-
125
- The hook provides all that is required for triggering smart contract transactions. useScTransaction can also take a callback function as an argument.
123
+ Example with Smart Contract data payload. For example, when you want to call an endpoint on a custom smart contract.
126
124
127
125
``` jsx
128
- const { pending , triggerTx , transaction , txResult , error } = useScTransaction ({ cb });
126
+ import { U32Value , ContractFunction , ContractCallPayloadBuilder } from ' @multiversx/sdk-core' ;
127
+
128
+ const { triggerTx } = useTransaction ();
129
+
130
+ const handleSendTx = () => {
131
+ const data = new ContractCallPayloadBuilder ()
132
+ .setFunction (new ContractFunction (mintFunctionName))
133
+ .setArgs ([new U32Value (1 )])
134
+ .build ();
129
135
130
- const handleSendTx = useCallback (() => {
131
136
triggerTx ({
132
- smartContractAddress: process .env .NEXT_PUBLIC_MINT_SMART_CONTRACT_ADDRESS ,
133
- func: process .env .NEXT_PUBLIC_MINT_FUNCTION_NAME ,
137
+ address: mintSmartContractAddress,
134
138
gasLimit: 14000000 ,
135
- args : [ new U32Value ( 1 )] ,
136
- value : process . env . NEXT_PUBLIC_MINT_PAYMENT_PER_TOKEN ,
139
+ value : Number (mintPaymentPerToken) ,
140
+ data
137
141
});
138
- }, [triggerTx]) ;
142
+ };
139
143
```
140
144
141
145
#### useScQuery()
0 commit comments