1+ import {
2+ AbiRegistry ,
3+ SmartContractTransactionsFactory ,
4+ TransactionsFactoryConfig
5+ } from '@multiversx/sdk-core/out' ;
16import { useCallback , useState } from 'react' ;
27import { contractAddress } from 'config' ;
8+ import pingPongAbi from 'contracts/ping-pong.abi.json' ;
39import { signAndSendTransactions } from 'helpers/signAndSendTransactions' ;
410import {
511 Address ,
@@ -19,8 +25,6 @@ import {
1925 PingRawProps ,
2026 PongRawProps
2127} from 'types/pingPong.types' ;
22- import { getChainId } from 'utils/getChainId' ;
23- import { smartContract } from 'utils/smartContract' ;
2428
2529type PingPongTransactionProps = {
2630 type : SessionEnum ;
@@ -89,17 +93,32 @@ export const useSendPingPongTransaction = ({
8993 [ ]
9094 ) ;
9195
96+ const getSmartContractFactory = async ( ) => {
97+ const abi = AbiRegistry . create ( pingPongAbi ) ;
98+ const scFactory = new SmartContractTransactionsFactory ( {
99+ config : new TransactionsFactoryConfig ( {
100+ chainID : network . chainId
101+ } ) ,
102+ abi
103+ } ) ;
104+
105+ return scFactory ;
106+ } ;
107+
92108 const sendPingTransactionFromAbi = useCallback (
93109 async ( { amount, callbackRoute } : PingRawProps ) => {
94110 clearAllTransactions ( ) ;
95111
96- const pingTransaction = smartContract . methodsExplicit
97- . ping ( )
98- . withSender ( new Address ( address ) )
99- . withValue ( amount ?? '0' )
100- . withGasLimit ( 60000000 )
101- . withChainID ( getChainId ( ) )
102- . buildTransaction ( ) ;
112+ const scFactory = await getSmartContractFactory ( ) ;
113+ const pingTransaction = scFactory . createTransactionForExecute (
114+ new Address ( address ) ,
115+ {
116+ gasLimit : BigInt ( 60000000 ) ,
117+ function : 'ping' ,
118+ contract : new Address ( contractAddress ) ,
119+ nativeTransferAmount : BigInt ( amount )
120+ }
121+ ) ;
103122
104123 const sessionId = await signAndSendTransactions ( {
105124 transactions : [ pingTransaction ] ,
@@ -161,13 +180,16 @@ export const useSendPingPongTransaction = ({
161180 async ( { callbackRoute } : PongRawProps ) => {
162181 clearAllTransactions ( ) ;
163182
164- const pongTransaction = smartContract . methodsExplicit
165- . pong ( )
166- . withSender ( new Address ( address ) )
167- . withValue ( '0' )
168- . withGasLimit ( 60000000 )
169- . withChainID ( getChainId ( ) )
170- . buildTransaction ( ) ;
183+ const scFactory = await getSmartContractFactory ( ) ;
184+ const pongTransaction = scFactory . createTransactionForExecute (
185+ new Address ( address ) ,
186+ {
187+ gasLimit : BigInt ( 60000000 ) ,
188+ function : 'pong' ,
189+ contract : new Address ( contractAddress ) ,
190+ nativeTransferAmount : BigInt ( 0 )
191+ }
192+ ) ;
171193
172194 const sessionId = await signAndSendTransactions ( {
173195 transactions : [ pongTransaction ] ,
0 commit comments