npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@litprotocol-dev/contracts-sdk

v2.0.23

Published

ContractsSDK is a bundled package that allows you to make calls to Lit Protocol smart contracts. Some contracts come with additional abstracted functions that can be accessed by appending `Util` to the contract variable name, for example, `pkpNftContract`

Downloads

12

Readme

Lit Protocol Contracts SDK (Typescript)

ContractsSDK is a bundled package that allows you to make calls to Lit Protocol smart contracts. Some contracts come with additional abstracted functions that can be accessed by appending Util to the contract variable name, for example, pkpNftContract becomes pkpNftContractUtil.

Demo: https://demo-contracts-sdk-react.vercel.app/

Installation

yarn add @litprotocol-dev/contracts-sdk

Vanilla JS

<script src="https://cdn.jsdelivr.net/npm/@litprotocol-dev/contracts-sdk-vanilla/contracts-sdk.js"></script>
<script>
  (async () => {
    const { LitContracts } = LitJsSdk_contractsSdk;

    const litContracts = new LitContracts();
    await litContracts.connect();
  })();
</script>

Quick Start

Initialize an instance

// -- Default
// Environments:
//    -- [NodeJs]: It will generate a random private key to create a signer
//    -- [Browser]: It will use window.ethereum as a signer
// RPC: https://matic-mumbai.chainstacklabs.com
const litContracts = new LitContracts();
await litContracts.connect();

// -- custom rpc
const litContracts = new LitContracts({
  rpc: 'https://localhost:3000',
});

// -- custom signer
const privateKey =
  '0x4cc303e56f1ff14e762a33534d7fbaa8a76e52509fd96373f24045baae99cc38';
const provider = new ethers.providers.JsonRpcProvider(
  'https://matic-mumbai.chainstacklabs.com'
);
const signer = new ethers.Wallet(privateKey, provider);
const litContracts = new LitContracts({ signer });
await litContracts.connect();

Usage

// -------------------- READ --------------------
// -- calling the pkpNftContract raw functions
const PKP_TOKEN_ID = BigNumber.from('38350640033302...4285614');
const PKP_ETH_ADDRESS = '0x...123';

let ethAddress = await litContracts.pkpNftContract.getEthAddress(PKP_TOKEN_ID);
let pkpPubKey = await litContracts.pkpNftContract.getPubKey(PKP_TOKEN_ID);
let mintCost = await litContracts.pkpNftContract.mintCost();

// -- calling the pkpPermissionsContract raw functions
let permittedAddresses = await litContracts.pkpPermissionsContract(
  PKP_TOKEN_ID
);

// -------------------- ADDTIONAL READS --------------------
let ipfsIsPermitted =
  await litContracts.pkpPermissionsContractUtil.read.isPermittedAction(
    PKP_TOKEN_ID,
    'QmZKLGf3vgYsboM7WVUS9X56cJSdLzQVacNp841wmEDRkW'
  );

let addressTokens =
  await litContracts.pkpNftContractUtil.read.getTokensByAddress(PKP_ETH_ADDRES);

let last2TokensOfTheContract =
  await litContracts.pkpNftContractUtil.read.getToken(2);

// -------------------- WRITE --------------------
const tx = await contracts.pkpNftContract.mintNext(2, { value: mintCost });
const tx = await contracts.pkpNftContract.mintNext(2, {
  // The maximum units of gas for the transaction to use
  gasLimit: 23000,

  // The price (in wei) per unit of gas
  gasPrice: ethers.utils.parseUnits('9.0', 'gwei'),

  // The nonce to use in the transaction
  nonce: 123,

  // The amount to send with the transaction (i.e. msg.value)
  value: ethers.utils.parseEther('1.0'),

  // The chain ID (or network ID) to use
  chainId: 1,
});

Other contracts can be accessed from litContracts.

Dev scripts

Config file

lit-contracts.config.json

If the directory structures have been changed on the LitNodeContracts repo, you will need to edit the config file.

{
  "root": "https://raw.githubusercontent.com/LIT-Protocol/LitNodeContracts/main/",
  "contracts": "deployed_contracts_serrano.json",
  "abis": {
    "dir": "deployments/mumbai_80001/",
    "ignoreProperties": ["metadata", "bytecode", "deployedBytecode"]
  }
}

Quick start

The gen-code and fetch-contracts actions are executed together in this action.

node ./packages/contracts-sdk/tools.mjs --update

fetch-contracts.mjs

This script fetches and processes ABI files for a set of deployed contracts. It writes the ABI files and contract data to the file system and runs a command to generate additional files based on the ABIs.

node ./packages/contracts-sdk/tools.mjs --fetch

gen-code.mjs

This script automatically generates a contracts-sdk.ts. It does this by reading the file names from a specified directory, generating import statements and declarations based on those file names, and replacing certain sections of the contracts-sdk.ts file with the generated content.

node ./packages/contracts-sdk/tools.mjs --gen