import { dynamicClient } from './dynamicClient'
import { SuiClient } from '@mysten/sui.js/client'
import { Transaction } from '@mysten/sui/transactions'
import { MIST_PER_SUI } from '@mysten/sui/utils';
export const sendSui = async (to: string, amountSui: string) => {
const wallet = dynamicClient.wallets.primary
if (!wallet) return
const networkUrl = await dynamicClient.sui.getNetworkUrl({ walletId: wallet.id })
const suiClient = new SuiClient({ url: networkUrl })
const signer = dynamicClient.sui.getSigner({ wallet })
const tx = new Transaction()
tx.setSender(wallet.address)
const [coin] = tx.splitCoins(tx.gas, [BigInt(Math.floor(Number(amountSui) * MIST_PER_SUI))])
tx.transferObjects([coin], to)
const { signature } = await signer.signTransaction(tx)
const txBytes = await tx.build({ client: suiClient as any })
const { digest } = await suiClient.executeTransactionBlock({ transactionBlock: txBytes, signature })
return digest
}