Vanilla JS/TS
JavaScript
Our team is currently working on this feature. If you experience any bugs, please let us know on our Discord. We appreciate your patience.
A common way to interact with blockchain is to make calls and send transactions from JavaScript, most often from a web browser. vlayer provides developer friendly JavaScript/TypeScript API - vlayer SDK. It combines well with the standard way of interacting with smart contracts.
Installation
To install vlayer SDK, run the following command in your JavaScript application
yarn add @vlayer/sdk
vlayer client
A vlayer client is an interface to vlayer JSON-RPC API methods to trigger and follow the status of proving. It also provides convenient access to specific vlayer features such as Web Proofs and Email Proofs.
Initialize a client with default prover.
import { createVlayerClient } from '@vlayer/sdk'
const vlayer = createVlayerClient();
Initialize a client with prover with specific url.
import { createVlayerClient } from '@vlayer/sdk'
const vlayer = createVlayerClient({
proverUrl: 'http://localhost:3000',
})
Proving
In order to start proving, we will need to provide:
address
- an address of prover contractproverAbi
- abi of prover contractfunctionName
- name of prover contract function to callargs
- an array of arguments tofunctionName
prover contract functionchainId
- id of the chain in whose context the prover contract call shall be executed
import { foundry } from 'viem/chains'
import { proverAbi } from './proverAbi'
const hash = await vlayer.prove({
address: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
proverAbi,
functionName: 'main',
args: ['0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', 123],
chainId: foundry,
})
Waiting for result
Wait for the proving to be finished, and then retrieve the result along with Proof.
const result = await vlayer.waitForProvingResult(hash);
Verification
Once we have obtained proving result, we can call verifier contract (below example demonstrates how to use createAnvilClient
function for that purpose).
import { verifierAbi } from './verifierAbi'
import { testHelpers } from '@vlayer/sdk'
testHelpers.createAnvilClient().writeContract({
abi: verifierAbi,
address,
account,
functionName: 'verify',
args: result,
})