Skip to content

Viem Implementation Does Not Preserve Types #6521

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

Closed
jbrower95 opened this issue Mar 22, 2025 · 3 comments
Closed

Viem Implementation Does Not Preserve Types #6521

jbrower95 opened this issue Mar 22, 2025 · 3 comments
Labels

Comments

@jbrower95
Copy link

jbrower95 commented Mar 22, 2025

  • https://github.com/thirdweb-dev/js/blob/main/packages/thirdweb/src/adapters/viem.ts#L308
  • WalletClient's result is not particularly usable with getContract() from viem as Viem's WalletClient is parameterized on the type, and your implementation does not preserve the relationship between the input chain and the outputted WalletClient.
  • The implementation also seems odd.. I feel like most people would use viem's toAccount as opposed to intercepting the RPC call and inspecting which operation to perform. Can probably slim the code down if you do this instead.

Overall this library wasn't usable for me, probably going to rip thirdweb out. Once a connection is established to one of the walletProviders, I'd rather use Viem directly than deal with duplicate abstractions everywhere.

Is there any easier way to do any of this?

const activeWallet = useActiveWallet();
if (activeWallet) {
const walletClient = viemAdapter.wallet.toViem({
    wallet: activeWallet, // see: https://portal.thirdweb.com/typescript/v5/wallets
    client: client,
    chain: baseSepolia,
  });
  const contract = getContract({client: walletClient, address: Addresses.MyContract as `0x${string}`, abi: MyContractAbi}); 
}
// <--- results in an error on the typing of Client that is incredibly long.

// Type 'Chain' is not assignable to type 'Chain | undefined'. is the core of it
Copy link

linear bot commented Mar 22, 2025

@joaquim-verges
Copy link
Member

Good callout, might switch to use toAccount instead (PR also welcome!)

the error you're getting is likely because of a mismatch of your version of viem and the one we depend on. If you align those i think it should remove the type error.

Btw curious what you're trying to do? Are you trying to use thirdweb in-app wallets, but viem for onchain interactions?

not sure if applicable for you, but if that's what you're trying to do I recommend using our wagmi adapter

Copy link
Contributor

github-actions bot commented Apr 1, 2025

This issue has been inactive for 7 days. It is now marked as stale and will be closed in 2 days if no further activity occurs.

@github-actions github-actions bot added the Stale label Apr 1, 2025
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants