Support Deployless Reads
#4160
-
Deployless Reads are supports by Viem, and it would be nice to have Wagmi support for the same functionality via ReadContract rather than extracting the underlying viem client. |
Beta Was this translation helpful? Give feedback.
Answered by
tmm
Jul 22, 2024
Replies: 1 comment 2 replies
-
It's already supported, just hasn't been carried over to the Wagmi docs yet. (PR welcome for that!) import { encodeFunctionData, parseAbi } from 'viem'
import { useReadContract } from 'wagmi'
// Bytecode
const result = useReadContract({
abi: parseAbi(['function name() view returns (string)']),
code: '0x...', // Accessible here: https://etherscan.io/address/0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2#code
functionName: 'name',
})
// Deploy Factory
const account = {
address: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
abi: parseAbi(['function entryPoint() view returns (address)']),
} as const
const result2 = useReadContract({
// Address of the Smart Account deployer (factory).
factory: '0xE8Df82fA4E10e6A12a9Dab552bceA2acd26De9bb',
// Function to execute on the factory to deploy the Smart Account.
factoryData: encodeFunctionData({
abi: parseAbi(['function createAccount(address owner, uint256 salt)']),
functionName: 'createAccount',
args: [account.address, 0n],
}),
// Function to call on the Smart Account.
abi: account.abi,
address: account.address,
functionName: 'entryPoint',
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
hammeiam
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's already supported, just hasn't been carried over to the Wagmi docs yet. (PR welcome for that!)
TypeScript Playground