Skip to content

Latest commit

 

History

History
232 lines (200 loc) · 6.12 KB

README.md

File metadata and controls

232 lines (200 loc) · 6.12 KB

node-artblocks

npm CircleCI Node.js Package GitHub package.json version GitPOAPs

An open source node package for reading on-chain Art Blocks data and recreating generative art projects. By default the package reads data via the ArtBlocks Subgraph. For those using other languages, use this package as a how-to guide for working directly with ArtBlocks on-chain data.

Installation

npm i artblocks

Usage

import ArtBlocks from 'artblocks'

// Ethereum mainnet
let artblocks = new ArtBlocks("thegraph", "mainnet")

// Artist staging projects
// Please refrain from sharing these projects publicly
let artblocks = new ArtBlocks("thegraph", "goerli")

// Flex contracts
let artblocks = new ArtBlocks("thegraph", "goerli", contracts=["<contract_address>"] flex=true)

Methods

Available Projects

const response = artblocks.projects()
Promise {
  [
    { id: 0, name: 'Chromie Squiggle' },
    { id: 1, name: 'Genesis' },
    { id: 2, name: 'Construction Token' },
    { id: 3, name: 'Cryptoblots' },
    { id: 4, name: 'Dynamic Slices' },
    { id: 5, name: 'Variant Plan' },
    { id: 6, name: 'View Card' },
    { id: 7, name: 'Elevated Deconstructions' },
    { id: 8, name: 'Singularity' },
    { id: 9, name: 'Ignition' },
    ...
   ]
}

Project Metadata

const response = artblocks.project_metadata(0)
Promise {
  {
    id: 0,
    name: 'Chromie Squiggle',
    artist: 'Snowfro',
    curation_status: 'curated',
    description: 'Simple and easily identifiable, each squiggle embodies the soul of the Art Blocks platform. Consider each my personal signature as an artist, developer, and tinkerer. Public minting of the Chromie Squiggle is permanently paused. They are now reserved for manual distribution to collectors and community members over a longer period of time. Please visit OpenSea to explore Squiggles available on the secondary market.',
    license: 'NFT License',
    website: 'https://www.twitter.com/artonblockchain',
    paused: true,
    complete: false,
    locked: true,
    currency_symbol: 'ETH',
    price_eth: 0,
    invocations: 9257,
    invocations_max: 10000,
    contract: '0x059edd72cd353df5106d2b9cc5ab83a52287ac3a'
  }
}

Project Script

const response = artblocks.project_script(0)
Promise {
  {
    id: 0,
    name: 'Chromie Squiggle',
    last_updated: '1620363885',
    ependency: 'p5js',
    dependency_version: '1.0.0',
    dependency_url: '"https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js"',
    interactive: 'true',
    animation_length_sec: undefined,
    instructions: 'click to animate | space bar changes background color',
    script: 'let numHashes = tokenData.hashes.length;\n' +
      'let hashPairs = [];\n' +
      'for (let i = 0; i < numHashes; i++) {\n' +
      '     for (let j = 0; j < 32; j++) {\n' +
      '          hashPairs.push(tokenData.hashes[i].slice(2 + (j * 2), 4 + (j * 2)));\n' +
      '     }\n' +
      '}\n' +
      ...
  }
}

Token Metadata

const response = artblocks.token_metadata(0)
Promise {
  {
    project_id: 0,
    project_name: 'Chromie Squiggle',
    token_id: 0,
    token_invocation: 0,
    token_hash: '0x722899b10c66da3b72fb60a8e71df442ee1c004547ba2227d76bed357469b4ea'
  }
}

Token Script

const response = artblocks.token_script(0)
Promise {
  {
    token_id: 0,
    token_invocation: 0,
    token_dependencies: {
      dependency: 'p5js',
      dependency_version: '1.0.0',
      dependency_url: '"https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js"'
    },
    token_data: 'let tokenData = {"hashes":["0x722899b10c66da3b72fb60a8e71df442ee1c004547ba2227d76bed357469b4ea"], "tokenId":"0"}',
    token_script: 'let numHashes = tokenData.hashes.length;\n' +
      'let hashPairs = [];\n' +
      'for (let i = 0; i < numHashes; i++) {\n' +
      '     for (let j = 0; j < 32; j++) {\n' +
      '          hashPairs.push(tokenData.hashes[i].slice(2 + (j * 2), 4 + (j * 2)));\n' +
      '     }\n' +
      '}\n' +
      ...
  }
}

Token Generator

const response = artblocks.token_generator(0)
Promise {
  '<!DOCTYPE HTML>\n' +
    '<html lang="en">\n' +
    '  <head>\n' +
    '    <meta charset="utf-8">\n' +
    '    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js"></script>\n' +
    '    <script>let tokenData = {"hashes":["0x722899b10c66da3b72fb60a8e71df442ee1c004547ba2227d76bed357469b4ea"], "tokenId":"0"}</script>\n' +
    '    <script>let numHashes = tokenData.hashes.length;\n' +
    'let hashPairs = [];\n' +
    'for (let i = 0; i < numHashes; i++) {\n' +
    '     for (let j = 0; j < 32; j++) {\n' +
    '          hashPairs.push(tokenData.hashes[i].slice(2 + (j * 2), 4 + (j * 2)));\n' +
    '     }\n' +
    '}\n' +
    ...
}

Custom Queries

let x = `
{
  projects(
    first: 5,
    orderBy: projectId, 
    orderDirection: desc, 
    where: {curationStatus: "curated"}
  ) 
  {         
    projectId
    name
    artistName
    curationStatus
  }
}
`
const response = artblocks.custom(x)
Promise {
  projects: [
    {
      projectId: '225',
      name: 'Vortex',
      artistName: 'Jen Stark',
      curationStatus: 'curated'
    },
    {
      projectId: '215',
      name: 'Gazers',
      artistName: 'Matt Kane',
      curationStatus: 'curated'
    },
    ...
  ]
}