@@ -364,34 +364,11 @@ async function autodetectAdminType(sf, account) {
364364 throw new Error ( `Unknown admin contract type of account ${ account } ` ) ;
365365}
366366
367- // returns the Safe Tx Service URL or throws if none available
368- // source: https://github.com/safe-global/safe-docs/blob/main/pages/api-supported-networks.md?plain=1
369- function getSafeTxServiceUrl ( chainId ) {
370- const safeChainNames = {
371- // mainnets
372- 1 : "mainnet" ,
373- 10 : "optimism" ,
374- 56 : "bsc" ,
375- 100 : "gnosis-chain" ,
376- 137 : "polygon" ,
377- 8453 : "base" ,
378- 42161 : "arbitrum" ,
379- 42220 : "celo" ,
380- 43114 : "avalanche" ,
381- // testnets
382- 11155111 : "sepolia"
383- } ;
384- if ( safeChainNames [ chainId ] === undefined ) {
385- throw new Error ( `no Safe tx service url known for chainId ${ chainId } ` ) ;
386- }
387- return `https://safe-transaction-${ safeChainNames [ chainId ] } .safe.global` ;
388- }
389-
390367// safeTxData is the ABI encoded transaction data of the inner call to be made by the Safe
391368async function executeSafeTransaction ( safeAddr , targetContractAddr , safeTxData ) {
392369 const Web3Adapter = require ( '@safe-global/safe-web3-lib' ) . default ;
393370 const Safe = require ( '@safe-global/safe-core-sdk' ) . default ;
394- const SafeServiceClient = require ( '@safe-global/safe-service-client ' ) . default ;
371+ const SafeApiKit = require ( '@safe-global/api-kit ' ) . default ;
395372
396373 const safeOwner = ( await web3 . eth . getAccounts ( ) ) [ 0 ] ; // tx sender
397374 console . log ( "Safe signer being used:" , safeOwner ) ;
@@ -403,18 +380,18 @@ async function executeSafeTransaction(safeAddr, targetContractAddr, safeTxData)
403380
404381 const safeSdk = await Safe . create ( { ethAdapter : ethAdapterOwner1 , safeAddress : safeAddr } ) ;
405382
406- const safeService = new SafeServiceClient ( {
407- txServiceUrl : getSafeTxServiceUrl ( await web3 . eth . getChainId ( ) ) ,
408- ethAdapter : ethAdapterOwner1
383+ const chainId = await web3 . eth . getChainId ( ) ;
384+ const apiKit = new SafeApiKit ( {
385+ chainId : BigInt ( chainId ) ,
386+ apiKey : process . env . SAFE_API_KEY // Required for auth/default service
409387 } ) ;
410388
411389 const data = safeTxData ;
412- const nextNonce = await safeService . getNextNonce ( safeAddr ) ;
390+
413391 const safeTransactionData = {
414392 to : targetContractAddr ,
415393 value : 0 ,
416394 data : data ,
417- nonce : process . env . SAFE_REPLACE_LAST_TX ? nextNonce - 1 : nextNonce
418395 } ;
419396 const safeTransaction = await safeSdk . createTransaction ( { safeTransactionData } ) ;
420397 console . log ( "Safe tx:" , safeTransaction ) ;
@@ -424,26 +401,24 @@ async function executeSafeTransaction(safeAddr, targetContractAddr, safeTxData)
424401 const signature = await safeSdk . signTransactionHash ( safeTxHash ) ;
425402 console . log ( "Signature:" , signature ) ;
426403
427- const transactionConfig = {
404+ const pendingTxsBefore = await apiKit . getPendingTransactions ( safeAddr ) ;
405+
406+ // according to the docs this should return the tx hash, but always returns undefined although succeeding
407+ const ret = await apiKit . proposeTransaction ( {
428408 safeAddress : safeAddr ,
429409 safeTransactionData : safeTransaction . data ,
430410 safeTxHash : safeTxHash ,
431411 senderAddress : safeOwner ,
432412 senderSignature : signature . data ,
433413 origin : "ops-scripts"
434- } ;
435-
436- const pendingTxsBefore = await safeService . getPendingTransactions ( safeAddr ) ;
437-
438- // according to the docs this should return the tx hash, but always returns undefined although succeeding
439- const ret = await safeService . proposeTransaction ( transactionConfig ) ;
414+ } ) ;
440415 console . log ( "returned:" , ret ) ;
441416
442- const pendingTxsAfter = await safeService . getPendingTransactions ( safeAddr ) ;
443- console . log ( `pending txs before ${ pendingTxsBefore . count } , after ${ pendingTxsAfter . count } ` ) ;
417+ const pendingTxsAfter = await apiKit . getPendingTransactions ( safeAddr ) ;
418+ console . log ( `pending txs before ${ pendingTxsBefore . results . length } , after ${ pendingTxsAfter . results . length } ` ) ;
444419
445420 // workaround for verifying that the proposal was added
446- if ( ! pendingTxsAfter . count > pendingTxsBefore . count ) {
421+ if ( ! pendingTxsAfter . results . length > pendingTxsBefore . results . length ) {
447422 throw new Error ( "Safe pending transactions count didn't increase, propose may have failed!" ) ;
448423 }
449424}
0 commit comments