Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: like prepareWriteContract, allow walletClient for writeContract #3015

Closed
wants to merge 2 commits into from

Conversation

0xFlicker
Copy link
Contributor

@0xFlicker 0xFlicker commented Sep 17, 2023

Description

Adds walletClient as a parameter to writeContract

This parameter is supported by prepareWriteContract

I needed to make this change in order to get some custom scripts I wrote to work when using NodeJS + eth-provider + wagmi & friends

I made no updates to docs because the docs don't cover all of the input parameters to this function

This change lets me use viem + wagmi/cli generated code + eth-provider (to connect to desktop wallet frame.sh) together with code like this:

  const frame = ethProvider("frame");
  export const frameConnector = new InjectedConnector({
    options: {
      name: "Frame",
      getProvider: () => frame as any,
    },
  });
  const chain = [mainnet, sepolia, goerli].find(
    (chain) => chain.id === chainId
  );
  if (!chain) throw new Error(`Chain ${chainId} not found`);
  await frameConnector.connect({ chainId });
  const walletClient = createWalletClient({
    chain,
    transport: custom(frame),
  });
  const promiseClaimedProcessed = promiseClaimEvent({
    contractAddress: "0x8297AA011A99244A571190455CE61846806BF0ce",
    chainId,
  });
  // add a test allowance
  const allowanceConfig = await prepareWriteTestAllowance({
    chainId,
    account: claimingAddress,
    address: "0x8297AA011A99244A571190455CE61846806BF0ce",
    functionName: "claim",
    walletClient,
    args: [[bitcoinAddress]],
  });
  const testAllowanceResult = await writeTestAllowance({
    ...allowanceConfig,
    walletClient,
  });

otherwise I get an exception in writeTestAllowance because walletClient attempts to read from the global state, unlike prepare, which accepts from arguments

Additional Information

Your ENS/address:
0xflick.xyz

@changeset-bot
Copy link

changeset-bot bot commented Sep 17, 2023

🦋 Changeset detected

Latest commit: 2727349

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@wagmi/core Patch
wagmi Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Sep 17, 2023

@0xFlicker is attempting to deploy a commit to the wagmi Team on Vercel.

A member of the Team first needs to authorize it.

@0xFlicker
Copy link
Contributor Author

updated description with code why I made this change

only used currently in the context of an automated test, so not blocking me in any way

but also this change seems reasonable to me

@0xFlicker
Copy link
Contributor Author

I currently run some local scripts using this locally linked fork which also requires local linking global state @wagmi/* dependencies

@tmm
Copy link
Member

tmm commented Oct 11, 2023

Not going to change how this works at the moment. Wagmi v2 (see #3068) has a better abstraction for this so don't want to add this now and take it away once that is released.

@tmm tmm closed this Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants