useShieldedWrite
Send encrypted write transactions to shielded contracts
Last updated
import { useShieldedWriteContract } from 'seismic-react'
const abi = [
{
name: 'transfer',
type: 'function',
stateMutability: 'nonpayable',
inputs: [
{ name: 'to', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
outputs: [],
},
] as const
function TransferToken() {
const { writeContract, isLoading, error, hash } = useShieldedWriteContract({
address: '0x1234567890abcdef1234567890abcdef12345678',
abi,
functionName: 'transfer',
args: ['0xRecipientAddress...', 1000n],
})
return (
<div>
<button onClick={writeContract} disabled={isLoading}>
{isLoading ? 'Sending...' : 'Transfer'}
</button>
{hash && <p>Transaction: {hash}</p>}
{error && <p>Error: {error.message}</p>}
</div>
)
}import { useShieldedWriteContract } from 'seismic-react'
import { useEffect } from 'react'
function WriteWithTracking() {
const { writeContract, hash, isLoading } = useShieldedWriteContract({
address: CONTRACT_ADDRESS,
abi,
functionName: 'increment',
})
useEffect(() => {
if (hash) {
console.log('Transaction confirmed:', hash)
}
}, [hash])
return (
<div>
<button onClick={writeContract} disabled={isLoading}>
Increment
</button>
{hash && (
<a href={`https://seismic-testnet.socialscan.io/tx/${hash}`} target="_blank" rel="noreferrer">
View on explorer
</a>
)}
</div>
)
}import { useShieldedWriteContract } from 'seismic-react'
function WriteWithStates() {
const { writeContract, isLoading, error, hash } = useShieldedWriteContract({
address: CONTRACT_ADDRESS,
abi,
functionName: 'setNumber',
args: [42n],
})
return (
<div>
<button onClick={writeContract} disabled={isLoading}>
{isLoading ? 'Encrypting & sending...' : 'Set Number'}
</button>
{isLoading && <p>Transaction in progress...</p>}
{error && <p style={{ color: 'red' }}>Failed: {error.message}</p>}
{hash && <p style={{ color: 'green' }}>Success: {hash}</p>}
</div>
)
}import { useShieldedWriteContract } from 'seismic-react'
function WriteWithGasOverride() {
const { writeContract, isLoading } = useShieldedWriteContract({
address: CONTRACT_ADDRESS,
abi,
functionName: 'expensiveOperation',
gas: 500_000n,
gasPrice: 20_000_000_000n,
})
return (
<button onClick={writeContract} disabled={isLoading}>
Execute
</button>
)
}