bug: can't read contract using useContractRead
Is there an existing issue for this?
- [X] I have searched the existing issues
Package Version
0.6.8
Current Behavior
I'm trying to check a token allowance using the useContractRead hook, but nothing happens, neither error nor loading variables are ever set to true, no error is thrown. Console stays empty.
Expected Behavior
Expected the allowance to be fetched or an error to be thrown.
Steps To Reproduce
It's just a create-react-app with wagmi. Here is a minimal reproducible example:
App.js
import {
WagmiConfig,
createClient,
defaultChains,
configureChains,
chain,
useContractEvent,
} from 'wagmi'
import { infuraProvider } from 'wagmi/providers/infura'
import { publicProvider } from 'wagmi/providers/public'
import { MetaMaskConnector } from 'wagmi/connectors/metaMask'
import { MRE } from './profile/MRE';
import { MRE2 } from './profile/MRE2';
const { chains, provider, webSocketProvider } = configureChains([chain.sepolia, chain.goerli],
[publicProvider()])
// Set up client
const client = createClient({
autoConnect: true,
connectors: [
new MetaMaskConnector({ chains }),
],
provider,
webSocketProvider,
})
function App() {
return (
<WagmiConfig client={client}>
<MRE2 />
</WagmiConfig>
)
}
export default App;
./profile/MRE2.js
import { useContractRead } from 'wagmi'
const abi = [{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
]
export function MRE2() {
const { data: allowance, isError: allowanceError, isLoading: allowanceLoading } = useContractRead({
address: "0x69BAf555AE5911A44192B284C7B09cbfCEae94Dc", // sep token
abi: abi,
functionName: "allowance",
args: ["0x5d8238675B516cf6e0841082fD78924F8320E4Fc", "0x03D3966ec2f5F058DC9f0D7bFfbc9b22426283C4"],
onSettled(data, error) {
console.log('Settled', { data, error })
},
});
}
Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)
No response
Anything else?
I'm sure it's something that I'm doing wrong, but I can't pin point it. I'd like to add that I am able to send transactions and use nearly all other hooks without any trouble. Also, the contract in question is in the Sepolia network.
I found the solution.
The addressOrName and contractInterface contract hooks where renamed to address and abi in 0.7.x.
I am using 0.6.x, however the 0.6.x examples in the docs are wrongly using the new version's names.
Closing.
I found the solution. The
addressOrNameandcontractInterfacecontract hooks where renamed toaddressandabiin 0.7.x. I am using 0.6.x, however the 0.6.x examples in the docs are wrongly using the new version's names.Closing.
thanks that was not intuitive and solved my issue of not getting any results from useContractRead
I'm facing the same issue.
"wagmi": "^1.3.9"
Same here. Anybody? @sayhicoelho any updates?
This issue has been locked since it has been closed for more than 14 days.
If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest wagmi version. If you have any other comments you can create a new discussion.