Current collected state Current
Observed since 21 Oct, 09:01 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
0xkey Helpers to work with Viem
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.
$ 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);
});
Copy .env.example to .env
$ cp .env.example .env
Start the Anvil node in one shell:
$PATH
$ export PATH="$PATH:$HOME/.foundry/bin"
$ source ~/.zshrc
foundryup to install Anvil
$ foundryup
$ pnpm anvil
Run the tests in a new shell:
$ pnpm test
@0xkey-io/example-with-viem: example using this package to create, sign, and broadcast a transaction on Sepolia (Ethereum testnet)@0xkey-io/http: lower-level fully typed HTTP client for interacting with ZeroXKey API@0xkey-io/api-key-stamper: package to authenticate to ZeroXKey using API key credentials@0xkey-io/webauthn-stamper: package to authenticate to ZeroXKey using Webauthn/passkeys.Download counts and popularity will appear here as the collector receives them.
This describes our collected data; it is not a security assessment.
Observed since 21 Oct, 09:01 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:bc811b3b3b6637d817221152da796bdc13fabd53a246026e556d3c0492fa48b1