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 @lit-protocol/contracts-sdk
Vanilla JS
<script src="https://cdn.jsdelivr.net/npm/@lit-protocol/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
const litContracts = new LitContracts();
await litContracts.connect();
const litContracts = new LitContracts({
rpc: 'https://localhost:3000',
});
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
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();
let permittedAddresses = await litContracts.pkpPermissionsContract(
PKP_TOKEN_ID
);
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);
const tx = await contracts.pkpNftContract.mintNext(2, { value: mintCost });
const tx = await contracts.pkpNftContract.mintNext(2, {
gasLimit: 23000,
gasPrice: ethers.utils.parseUnits('9.0', 'gwei'),
nonce: 123,
value: ethers.utils.parseEther('1.0'),
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
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 --fetch
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 --gen