diff --git a/v4-client-js/src/clients/native.ts b/v4-client-js/src/clients/native.ts index b412cd72..1485e1e0 100644 --- a/v4-client-js/src/clients/native.ts +++ b/v4-client-js/src/clients/native.ts @@ -1176,9 +1176,7 @@ export async function cctpMultiMsgWithdraw(cosmosPayload: string): Promise { + if (!this.stargateClient) { + throw new Error('NobleClient stargateClient not initialized'); + } + + if (this.wallet?.address === undefined) { + throw new Error('NobleClient wallet not initialized'); + } + // Simulate to get the gas estimate + const fee = await this.simulateTransaction(messages, gasPrice, memo ?? this.defaultClientMemo); + + // Sign and broadcast the transaction + const txHashObj = await this.stargateClient.sign( + this.wallet.address, + messages, + fee, + memo ?? this.defaultClientMemo, + ); + const serializedTx = TxRaw.encode(txHashObj).finish() + const base64Tx = toBase64(serializedTx) + const skipSubmitResponse = await this.post( + `/v2/tx/submit`, + {}, + JSON.stringify({ + tx: base64Tx, + chain_id: chainId + }) + ) + const { data: { tx_hash: txHash }} = skipSubmitResponse; + const formattedResponse = { + transactionHash: txHash, + code: 0, + ...skipSubmitResponse.data + } + return formattedResponse + } + async send( messages: EncodeObject[], - gasPrice: GasPrice = GasPrice.fromString('0.1uusdc'), + gasPrice: GasPrice = this.defaultGasPrice, memo?: string, ): Promise { if (!this.stargateClient) { @@ -90,7 +144,7 @@ export class NobleClient { async simulateTransaction( messages: readonly EncodeObject[], - gasPrice: GasPrice = GasPrice.fromString('0.1uusdc'), + gasPrice: GasPrice = this.defaultGasPrice, memo?: string, ): Promise { if (!this.stargateClient) {