Skip to content

Viem Implementation Does Not Preserve Types #6521

Closed as not planned
Closed as not planned
@jbrower95

Description

@jbrower95
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions