0.4.1 • Published 1 month ago

@sovereign-sdk/web3 v0.4.1

Weekly downloads
-
License
-
Repository
github
Last release
1 month ago

@sovereign-sdk/web3

npm version CI

A TypeScript client library for interacting with Sovereign SDK rollups.

Installation

npm install @sovereign-sdk/web3

Features

  • 🔄 Type-safe transaction submission and signing
  • 🔍 Runtime call simulation for gas estimation
  • 📦 Borsh serialization with schema validation
  • 🎯 Strongly typed rollup interactions with customizable type specifications
  • 🌐 Full access to ledger, sequencer, and rollup APIs

Usage

Basic Setup

import { StandardRollup } from "@sovereign-sdk/web3";
import { newMetaMaskSnapSigner } from "@sovereign-sdk/signers";

// Initialize the rollup client
const rollup = new StandardRollup({
  url: "https://your-rollup-node.com",
  defaultTxDetails: {
    max_priority_fee_bips: 0,
    max_fee: 1000000,
    gas_limit: null,
    chain_id: 4321,
  },
});

// Initialize a signer
const signer = newMetaMaskSnapSigner({
  curve: "ed25519",
  schema: yourSchema,
  snapId: "npm:@sovereign-sdk/metamask-snap",
});

Submitting Transactions

// Submit a transaction
// Sends a `ValueSetter` call message of `SetValue` type.
// This particular call message has `value` and `gas` fields.
const result = await rollup.call(
  {
    value_setter: {
      set_value: {
        value: 100,
        gas: null,
      },
    },
  },
  { signer }
);

Type Safety

type MyRollupTypes = RollupTypeSpec<{
  RuntimeCall: {
    value_setter: {
      set_value: {
        value: number;
        gas: number[] | null;
      };
    };
  };
  // Add other type specifications as needed
}>;

const typedRollup = new StandardRollup<MyRollupTypes>({
  // ... config
});

// Now your calls will be type-checked!
const result = await typedRollup.call(
  {
    value_setter: {
      set_value: 100, // Type checked and automatically serialized to Borsh bytes
    },
  },
  { signer }
);

Simulation

// Simulate a call to estimate gas
const simulation = await rollup.simulate(
  {
    value_setter: {
      set_value: 100,
    },
  },
  {
    signer,
    txDetails: {
      max_priority_fee_bips: 1000,
      max_fee: 1000000,
      chain_id: 1,
    },
  }
);

API Reference

The package exports the following main components:

  • StandardRollup: The main client class for interacting with rollups
  • RollupTypeSpec: Type utility for creating type-safe rollup interactions
  • createSerializer: Function to create a Borsh serializer for your rollup schema

For detailed API documentation, please refer to the inline TypeScript documentation in the source code.

0.0.20

7 months ago

0.0.21

6 months ago

0.0.22

6 months ago

0.0.23

6 months ago

0.0.24

4 months ago

0.0.25

4 months ago

0.0.15

8 months ago

0.0.16

8 months ago

0.0.17

8 months ago

0.0.18

8 months ago

0.0.19

7 months ago

0.0.14

8 months ago

0.1.0

4 months ago

0.3.0

2 months ago

0.2.1

3 months ago

0.2.0

3 months ago

0.0.26

4 months ago

0.4.1

1 month ago

0.4.0

2 months ago

0.2.2

2 months ago

0.0.10

9 months ago

0.0.11

9 months ago

0.0.12

9 months ago

0.0.13

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.1

9 months ago