import React, { FC, useState } from 'react'
import { Button, Text, TextInput, View } from 'react-native'
import { usePortal } from '@portal-hq/core'
const NativeSendTx = () => {
const portal = usePortal()
const [toAddress, setToAddress] = useState('')
const [txHash, setTxHash] = useState('')
const handleSend = async () => {
try {
// Build the transaction using the simplified API
const { transaction } = await portal.api.buildTransaction(
toAddress, // recipient address
'NATIVE', // token type (native MON)
'0.001', // amount
'monad-testnet' // network
)
// Send the transaction
const newTxHash = await portal.request(
'eth_sendTransaction',
[transaction],
'eip155:10143'
)
setTxHash(newTxHash)
setToAddress('')
} catch (error) {
console.error('Failed to send transaction:', error)
}
}
3
return (
<View>
<Text>Send 0.001 MON</Text>
<TextInput
onChangeText={setToAddress}
placeholder="Enter recipient address"
value={toAddress}
/>
<View style={{ marginTop: 10 }}>
<Button
disabled={!portal || !toAddress || !toAddress.length}
onPress={handleSend}
title="Send MON"
/>
</View>
{txHash && txHash.length > 0 && (
<View>
<Text>Successfully sent transaction!</Text>
<Text>Transaction Hash: {txHash}</Text>
</View>
)}
</View>
)
}
export default NativeSendTx