import { Button } from 'react-native'
import { FC } from 'react'
import { dynamicClient } from '<path to client file>'
import { Transaction } from '@mysten/sui/transactions'
import { SuiClient } from '@mysten/sui.js/client'
interface SendSuiButtonProps {
destinationAddress: string
amount: string
}
/**
* Renders a button that sends SUI to a given address.
*/
const SendSuiButton: FC<SendSuiButtonProps> = ({ destinationAddress, amount }) => {
const send = async () => {
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 transferTransaction = new Transaction()
transferTransaction.setSender(wallet.address)
const [coin] = transferTransaction.splitCoins(transferTransaction.gas, [
BigInt(amount) * BigInt(1000000000) // Convert to MIST (SUI's smallest unit)
])
transferTransaction.transferObjects([coin], destinationAddress)
const { signature } = await signer.signTransaction(transferTransaction)
const txBytes = await transferTransaction.build({ client: suiClient })
const { digest } = await suiClient.executeTransactionBlock({
transactionBlock: txBytes,
signature,
})
console.log('Successful transaction digest:', digest)
}
return <Button title="Send SUI" onPress={send} />
}