yarn
yarn test
The Nouns SDK contains useful tooling for interacting with the Nouns protocol.
Get Contract Addresses
import { ChainId, getContractAddressesForChainOrThrow } from '@nouns/sdk';
const { nounsToken } = getContractAddressesForChainOrThrow(ChainId.Mainnet);
Get Contract Instances
import { ChainId, getContractsForChainOrThrow } from '@nouns/sdk';
const provider = new providers.JsonRpcProvider(RPC_URL);
const { nounsTokenContract } = getContractsForChainOrThrow(ChainId.Mainnet, provider);
Get Contract ABIs
import { NounsTokenABI } from '@nouns/sdk';
Run-length Encode Images
import { PNGCollectionEncoder } from '@nouns/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 '@nouns/sdk';
const svg = buildSVG(RLE_PARTS, PALETTE_COLORS, BACKGROUND_COLOR);