I'm using Rainbowkit latest, alongside wagmi hooks v2.5.7, couldn't find an obvious problem, but I couldn't interact with my smart contract either basically, the error I'm receiving is that write is not a function any help is much appreciated, thank you
import React, { useState } from "react"
import { useAccount, useContractWrite } from "wagmi"
import { Button, Input, Text } from "@nextui-org/react"
import {
presaleAdr as contractAddress,
presale_ABI as contractABI,
} from "@/constants/presaleAdr"
function ModifyRate() {
const [newRate, setNewRate] = useState("")
const [error, setError] = useState("")
const { address, isConnected } = useAccount()
const {
write,
isLoading,
error: writeError,
} = useContractWrite({
addressOrName: contractAddress,
contractInterface: contractABI,
functionName: "adjustRates",
args: [newRate ? BigInt(newRate) : 0],
onSettled(data, error) {
if (error) {
console.error("Transaction Error:", error)
setError(error.message || "Adjustment failed.")
} else {
console.log("Transaction Success:", data)
setError("")
}
},
})
const handleAdjustRates = async () => {
setError("")
if (!isConnected) {
setError("Please connect your wallet first.")
return
}
if (!newRate) {
setError("Please enter a new rate.")
return
}
try {
const tx = await write()
console.log("Transaction initiated:", tx)
} catch (err) {
console.error("Adjustment failed:", err)
setError(err.message || "An unexpected error occurred.")
}
}
return (
<div className="w-1/2 m-auto h-auto">
<Input
clearable
bordered
fullWidth
color="primary"
size="lg"
placeholder="Enter the new rate"
value={newRate}
onChange={(e) => setNewRate(e.target.value)}
disabled={isLoading}
/>
<Button
auto
disabled={isLoading || !newRate || !isConnected}
onClick={handleAdjustRates}
>
{isLoading ? "Processing..." : "Adjust Rate"}
</Button>
{writeError && <Text color="error">{writeError.message}</Text>}
</div>
)
}
export default ModifyRate
` function ModifyRate() {
const [newRate, setNewRate] = useState("")
const [error, setError] = useState("")
const { address, isConnected } = useAccount()
const {
write,
isLoading,
error: writeError,
} = useContractWrite({
addressOrName: contractAddress,
contractInterface: contractABI,
functionName: "adjustRates",
args: [newRate ? BigInt(newRate) : 0],
onSettled(data, error) {
if (error) {
console.error("Transaction Error:", error)
setError(error.message || "Adjustment failed.")
} else {
console.log("Transaction Success:", data)
setError("")
}
},
})
const handleAdjustRates = async () => {
setError("")
if (!isConnected) {
setError("Please connect your wallet first.")
return
}
if (!newRate) {
setError("Please enter a new rate.")
return
}
try {
const tx = await write()
console.log("Transaction initiated:", tx)
} catch (err) {
console.error("Adjustment failed:", err)
setError(err.message || "An unexpected error occurred.")
}
}`
` mainly this is the problem, I used the old useSginer etc, now it's just nonfunctional and wagmi's migration guide is sooo baaad