I am trying to interact with a smart contract from a front-end web app using viem.
I am successfully creating a Wallet Client with my wallet address, but when I call some of its methods, I get the following error:
MethodNotFoundRpcError: The method does not exist / is not available.
Also, the only method that does not throw error, is not returning the expected result.
Here is my code (with each error presented as a comment):
import {
createPublicClient,
createWalletClient,
getContract,
http,
} from 'viem'
import { cronosTestnet } from 'viem/chains'
const account = '0x...' // My wallet's address
const walletClient = createWalletClient({
account,
chain: cronosTestnet,
transport: http()
})
try {
const accounts = await walletClient.getAddresses()
console.log(accounts)
// []
// Expected an array with the address I passed to walletClient, instead of an empty array
} catch(e) {
console.log(e)
}
try {
const accounts = await walletClient.requestAddresses()
} catch(e) {
console.log(e)
// MethodNotFoundRpcError: The method does not exist / is not available.
// Request body: {"method":"eth_requestAccounts"}
// Details: the method eth_requestAccounts does not exist/is not available
// Version: [email protected]
}
try {
const permissions = await walletClient.getPermissions()
} catch(e) {
console.log(e)
// MethodNotFoundRpcError: The method does not exist / is not available.
// Request body: {"method":"wallet_getPermissions"}
// Details: the method wallet_getPermissions does not exist/is not available
// Version: [email protected]
}
I have tried this with a MetaMask wallet and a crypto.com DeFi wallet, with the exact same results in both cases.
Any ideas about what I am doing wrong?