Javascript Library

Lagrange Labs develops and maintains the LagrangeJS SDK, a Javascript SDK that enable developers to easily integrate front end applications with Lagrange State Proofs. The LagrangeJS SDK is open source and will be launched concurrently with the public Lagrange Protocol Testnet launch.

npm install @LagrangeJS

Single-Chain State Proofs:

Using the LagrangeJS SDK, front end applications can easily connect users' browsers to the network of Lagrange Nodes. Once connected, client side applications can receive state proofs from Lagrange Committees for the chains that they are interested in. Once generated, these proofs can be easily verified by any contract integrated with the Lagrange Protocol or within supported cross-chain bridges and messaging protocols.

const providerUrl = {
  arbitrum: "https://arbitrum-mainnet.infura.io/v3/PROJECT-ID",
};

const proofRequests = [
  {
    chain: 'Arbitrum',
    block: 10002030401,
  }
];

const lagrangeSDK = initializeSDK(providerUrl);

const arbitrumStateProofs = await lagrangeSDK.getProof(proofRequests); 
// This will return an array of state proofs

Multi-Chain State Proofs:

The Lagrange SDK also makes it simple to generate state proofs across more than one chain concurrently. These multi-chain proofs enable DApps integrated with the Lagrange Protocol to nest multiple state verifications into a single on-chain transaction.

const providerUrl = {
    optimism: "https://optimism-mainnet.infura.io/v3/PROJECT-ID",
    base: "https://base-testnet.infura.io/v3/PROJECT-ID",
    arbitrum: "https://arbitrum-mainnet.infura.io/v3/PROJECT-ID"
};

const proofRequests = [
  {
    chain: 'Base',
    block: 4553170,
  },
  {
    chain: 'Optimism',
    block: 98960825,
  },
  {
    chain: 'Arbitrum',
    block: 10000000002,
  },
    
   ...
    
  {
    chain: 'Arbitrum',
    block: 10000000100,
  },
];

const lagrangeSDK = initializeSDK(providerUrl);

const multiStateProofs = await lagrangeSDK.getProof(proofRequests); 

//Integrate a state proof into any existing messaging protocol or bridge with a simple function call
const validity = await lagrangeSDK.verify({
    publicStatement: multiStateProofs.publicStatement,
    proof: multiStateProofs.proof
})

//Or verify a state proof on-chain through a simple verifier contract call
await lagrangeSDK.submitStateProof({
    chain: "ethereum",
    provider: rpc_provider,
    publicStatement: multiStateProofs.publicStatement,
    proof: multiStateProofs.proof,
})

Last updated