Skip to content

Latest commit

 

History

History

nouns-sdk

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@lilnounsdao/sdk

Development

Install dependencies

yarn

Run tests

yarn test

Usage

The Lil Nouns SDK contains useful tooling for interacting with the Lil Nouns and Nouns protocol.

Contracts

Get Contract Addresses

import { ChainId, getContractAddressesForChainOrThrow } from '@lilnounsdao/sdk';

const { nounsToken } = getContractAddressesForChainOrThrow(ChainId.Mainnet);

Get Contract Instances

import { ChainId, getContractsForChainOrThrow } from '@lilnounsdao/sdk';

const provider = new providers.JsonRpcProvider(RPC_URL);

const { nounsTokenContract } = getContractsForChainOrThrow(ChainId.Mainnet, provider);

Get Contract ABIs

import { NounsTokenABI } from '@lilnounsdao/sdk';

Images

Run-length Encode Images

import { PNGCollectionEncoder } from '@lilnounsdao/sdk';
import { readPngFile } from 'node-libpng';
import { promises as fs } from 'fs';
import path from 'path';

const DESTINATION = path.join(__dirname, './output/image-data.json');

const encode = async () => {
  const encoder = new PNGCollectionEncoder();

  const folders = ['bodies', 'accessories', 'heads', 'glasses'];
  for (const folder of folders) {
    const folderpath = path.join(__dirname, './images', folder);
    const files = await fs.readdir(folderpath);
    for (const file of files) {
      const image = await readPngFile(path.join(folderpath, file));
      encoder.encodeImage(file.replace(/\.png$/, ''), image, folder);
    }
  }
  await encoder.writeToFile(DESTINATION);
};

encode();

Create SVGs from Run-length Encoded Data

import { buildSVG } from '@lilnounsdao/sdk';

const svg = buildSVG(RLE_PARTS, PALETTE_COLORS, BACKGROUND_COLOR);