Catalog npm
PACKAGE EXPLORERView in registry

@0xkey-io/ethers

npm

0xkey Signer for Ethers

0xkeyethersethers.js
Versions collected4
Direct dependencies13From release 0.1.4
Last observed21 Oct, 09:00 UTC

README

Current package documentation

@0xkey-io/ethers

npm

ZeroXKey Signer for Ethers.

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

API Docs: https://docs.0xkey.io/

Getting started

$ npm install ethers @0xkey-io/ethers
import { ethers } from "ethers";
import { ZeroXKeySigner } from "@0xkey-io/ethers";
import { ZeroXKeyClient } from "@0xkey-io/http";
import { ApiKeyStamper } from "@0xkey-io/api-key-stamper";

async function main() {
  const network = "goerli";
  const provider = new ethers.providers.InfuraProvider(network);

  const zeroXKeyClient = 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: "...",
    }),
  );

  // Initialize a ZeroXKey Signer
  const zeroXKeySigner = new ZeroXKeySigner({
    client: zeroXKeyClient,
    organizationId: "...",
    signWith: "...",
  });

  // Connect it with a Provider (https://docs.ethers.org/v6/api/providers/)
  const connectedSigner = zeroXKeySigner.connect(provider);

  const chainId = await connectedSigner.getChainId();
  const address = await connectedSigner.getAddress();
  const balance = await connectedSigner.getBalance();
  const transactionCount = await connectedSigner.getTransactionCount();

  console.log(`Network\n\t${network} (chain ID ${chainId})`);
  console.log(`Address\n\t${address}`);
  console.log(`Balance\n\t${String(balance)}`);
  console.log(`Transaction count\n\t${transactionCount}`);

  const transactionRequest = {
    to: "0x2Ad9eA1E677949a536A270CEC812D6e868C88108",
    value: ethers.utils.parseEther("0.0001"),
    type: 2,
  };

  const signedTx = await connectedSigner.signTransaction(transactionRequest);

  console.log(`Signed transaction\n\t${signedTx}`);

  if (balance.isZero()) {
    let warningMessage =
      "\nWarning: the transaction won't be broadcasted because your account balance is zero.\n";
    if (network === "goerli") {
      warningMessage +=
        "Use https://goerlifaucet.com/ to request funds on Goerli, then run the script again.\n";
    }

    console.warn(warningMessage);
    return;
  }

  const sentTx = await connectedSigner.sendTransaction(transactionRequest);

  console.log(
    `Transaction sent!\n\thttps://${network}.etherscan.io/tx/${sentTx.hash}`,
  );
}

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

Testing (Local)

See .env.example to get your local testing environment right. Run pnpm jest to run the tests.

More examples

ExampleDescription
with-ethersCreate a new Ethereum address, then sign and broadcast a transaction using the Ethers signer with Infura
with-gnosisCreate new Ethereum addresses, configure a 3/3 Gnosis safe, and create + execute a transaction from it
with-uniswapSign and broadcast a Uniswap v3 trade using the Ethers signer with Infura
with-nonce-managerCreate a new Ethereum address, then sign and broadcast multiple transactions in a sequential or optimistic manner.
sweeperSweep funds from one address to a different address
deployerCompile and deploy a smart contract

See also

  • @0xkey-io/http: lower-level fully typed HTTP client for interacting with ZeroXKey API

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 202613
0.1.323 Jun 202613
0.1.122 May 202613
0.1.022 May 202613

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:00 UTC

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

Record identity

package:e78afcf9fb7d968cb9b3682bf64c9b3baf016b20afe973234b043b66b99770b2