0

I have the following code working, but I can't figure out how to make a .call or .send request after the web3Modal object has been initialized

Any help is really appreciated

Thanks in advance

import {
  EthereumClient,
  w3mConnectors,
  w3mProvider,
  WagmiCore,
  WagmiCoreChains,
  WagmiCoreConnectors,
} from "https://unpkg.com/@web3modal/[email protected]";

import { Web3Modal } from "https://unpkg.com/@web3modal/[email protected]";

// 0. Import wagmi dependencies
const { mainnet, polygon, avalanche, arbitrum } = WagmiCoreChains;
const { configureChains, createConfig, getAccount, getContract } = WagmiCore;

// 1. Define chains
const chains = [mainnet, polygon, avalanche, arbitrum];
const projectId = "eab...";

// 2. Configure wagmi client
const { publicClient } = configureChains(chains, [w3mProvider({ projectId })]);
const wagmiConfig = createConfig({
  autoConnect: true,
  connectors: [
    ...w3mConnectors({ chains, version: 2, projectId }),
    new WagmiCoreConnectors.CoinbaseWalletConnector({
      chains,
      options: {
        appName: "html wagmi example",
      },
    }),
  ],
  publicClient,
});

console.log("projectId", projectId);

// 3. Create ethereum and modal clients
const ethereumClient = new EthereumClient(wagmiConfig, chains);
export const web3Modal = new Web3Modal(
  {
    projectId
  },
  ethereumClient
);

1 Answer 1

0

what type of call do you want to make ? A contract call ? Or just an eth send ? As you're using wagmi, you can use wagmi's available actions like this example:

import { writeContract } from '@wagmi/core'

const { hash } = await writeContract({
  address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
  abi: wagmigotchiABI,
  functionName: 'claim',
  args: [69],
})

Check doc here: https://wagmi.sh/core/actions/writeContract

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.