EVVM JS is a powerful JavaScript/TypeScript library for seamless interaction with the EVVM. It simplifies common tasks such as payments, identity management, staking, and peer-to-peer swaps. Built with first-class TypeScript support, it offers a streamlined developer experience with robust type safety.
You can install EVVM JS using your favorite package manager:
bun add @evvm/evvm-js
# or
npm install @evvm/evvm-js
# or
yarn add @evvm/evvm-jsHere's a quick example of how to use EVVM JS to sign a payment action:
With Ethers.js
import { EVVM, execute } from "@evvm/evvm-js";
import { createSignerWithEthers } from "@evvm/evvm-js/signers";
import { ethers } from "ethers";
// 1. Create a signer
const provider = new ethers.JsonRpcProvider("YOUR_RPC_URL");
const privateKey = "YOUR_PRIVATE_KEY";
const wallet = new ethers.Wallet(privateKey, provider);
const signer = await createSignerWithEthers(wallet);
// 2. Instantiate the EVVM service
const evvm = new EVVM({
signer,
address: "EVVM_CONTRACT_ADDRESS",
chainId: 1,
evvmId: 1, // optional
});
// 3. Call a method to create a signed action
const signedAction = await evvm.pay({
to: "RECIPIENT_ADDRESS",
tokenAddress: "TOKEN_ADDRESS",
amount: 100n, // Use BigInt for amounts
priorityFee: 0n,
nonce: 1n,
priorityFlag: false,
});
// 4. Execute the signed action
const result = await execute(signer, signedAction);
console.log(result);With Viem
import { EVVM } from "@evvm/evvm-js";
import { createSignerWithViem } from "@evvm/evvm-js/signers";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
// 1. Create a signer
const account = privateKeyToAccount("YOUR_PRIVATE_KEY");
const client = createWalletClient({
account,
chain: mainnet,
transport: http("YOUR_RPC_URL"),
});
const signer = await createSignerWithViem(client);
// 2. Instantiate the EVVM service
const evvm = new EVVM({
signer,
address: "EVVM_CONTRACT_ADDRESS",
chainId: 1,
});
// Continue with steps 3 and 4 exactly as shown in the ethers.js exampleEVVM: Core EVVM service for creating signed actions (payments, identity, staking, swaps).NameService: Manage identities.Staking: Handle staking operations.P2PSwap: Perform peer-to-peer swaps.
Each service is instantiated with a signer and a contract address.
EVVM JS provides an abstracted ISigner interface that allows seamless integration with various client-side Ethereum libraries. Helper functions are provided to create ISigner instances from ethers.js and viem wallets:
createSignerWithEthers: Creates a signer from anethers.jswallet.createSignerWithViem: Creates a signer from aviemwallet client.
This project uses bun for package management and scripting.
bun installbun testbun run buildContributions are welcome! Please open an issue or submit a pull request on our GitHub repository.