Catalog npm
PACKAGE EXPLORERView in registry

@0xkey-io/viem

npm

0xkey Helpers to work with Viem

0xkeyaccountcustom accountsignerviemwallet
Versions collected4
Direct dependencies12From release 0.1.4
Last observed21 Oct, 09:01 UTC

README

Current package documentation

@0xkey-io/viem

npm

This package contains helpers to use Viem with ZeroXKey.

We provide a ZeroXKey Custom Account (signer) which implements the signing APIs expected by Viem clients.

If you need a lower-level, fully typed HTTP client for interacting with ZeroXKey API, check out @0xkey-io/http.

Getting started

$ npm install viem @0xkey-io/viem
import { createAccount } from "@0xkey-io/viem";
import { ZeroXKeyClient } from "@0xkey-io/http";
import { ApiKeyStamper } from "@0xkey-io/api-key-stamper";
import { createWalletClient, http } from "viem";
import { sepolia } from "viem/chains";

async function main() {
  // Create a ZeroXKey HTTP client with API key credentials
  const httpClient = new ZeroXKeyClient(
    {
      baseUrl: "https://api.0xkey.io",
    },
    // This uses API key credentials.
    // If you're using passkeys, use `@0xkey-io/webauthn-stamper` to collect webauthn signatures:
    // new WebauthnStamper({...options...})
    new ApiKeyStamper({
      apiPublicKey: "...",
      apiPrivateKey: "...",
    }),
  );

  // Create the Viem custom account
  const zeroXKeyAccount = await createAccount({
    client: httpClient,
    organizationId: "...",
    signWith: "...",
    // optional; will be fetched from ZeroXKey if not provided
    ethereumAddress: "...",
  });

  // Below: standard Viem APIs are used, nothing special!

  const client = createWalletClient({
    account: zeroXKeyAccount,
    chain: sepolia,
    transport: http(`https://sepolia.infura.io/v3/$(YOUR_INFURA_API_KEY)`),
  });

  const transactionRequest = {
    to: "0x08d2b0a37F869FF76BACB5Bab3278E26ab7067B7" as `0x${string}`,
    value: 1000000000000000n, // 0.001 ETH
  };

  const txHash = await client.sendTransaction(transactionRequest);
  console.log(`Success! Transaction broadcast with hash ${txHash}`);
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
});

Testing (Local)

  1. Copy .env.example to .env

    $ cp .env.example .env
    
  2. Start the Anvil node in one shell:

    • Install Foundry & Anvil if you haven't done so already
    • Add Foundry to your $PATH
      $ export PATH="$PATH:$HOME/.foundry/bin"
      
    • Source your env e.g.
      $ source ~/.zshrc
      
    • Run foundryup to install Anvil
      $ foundryup
      
    • Start Anvil
      $ pnpm anvil
      
  3. Run the tests in a new shell:

    $ pnpm test
    

See also

Transaction types supported

  • ZeroXKey's Viem implementation now supports all transaction types: legacy, EIP-2930 (Type 1), EIP-1559 (Type 2), EIP-4844 (Type 3), and EIP-7702 (Type 4). See with-viem for examples of scripts that sign using those various types.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 4

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.4Registry latest15 Oct 202612
0.1.323 Jun 202612
0.1.122 May 202612
0.1.022 May 202612

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
0xkey-io/sdk-js

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 09:01 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:bc811b3b3b6637d817221152da796bdc13fabd53a246026e556d3c0492fa48b1