Skip to content

Instantly share code, notes, and snippets.

@fend25
fend25 / box_substrate_secret.ts
Created October 11, 2023 08:39
Example of safely save some secret info (polkadot mnemonic) in the local storage
import {Sr25519Account} from '@unique-nft/sr25519'
import {algorithms} from '@unique-nft/utils/address'
import {getRandomValues} from 'node:crypto' // remove for browser code
import {secretbox, secretbox_open} from 'tweetnacl-ts'
const textEncoder = new TextEncoder()
const textDecoder = new TextDecoder()
const mnemonic = Sr25519Account.generateMnemonic()
const mnemonicByteArray = textEncoder.encode(mnemonic)
@fend25
fend25 / connect_to_parachain.ts
Created July 18, 2023 08:59
substrate connect light node example connecting to parachain
import {ApiPromise} from '@polkadot/api'
import {ScProvider} from '@polkadot/rpc-provider'
import * as Sc from '@substrate/connect'
import jsonParachainSpec from './unique_chain_spec.json'
const parachainSpec = JSON.stringify(jsonParachainSpec)
const relayProvider = new ScProvider(Sc, Sc.WellKnownChain.polkadot)
const provider = new ScProvider(Sc, parachainSpec, relayProvider)
@fend25
fend25 / hardhat.config.ts
Last active July 13, 2023 11:29
A minimal demonstration of creating an empty collection and minting an empty token on Unique using hardhat.
import { HardhatUserConfig, task } from "hardhat/config"
import "@typechain/hardhat"
import * as dotenv from "dotenv"
dotenv.config()
const config: HardhatUserConfig = {
solidity: "0.8.21",
defaultNetwork: "localhost",
@fend25
fend25 / nesting.ts
Last active June 19, 2023 16:13
Example of minting nested tokens at once on the Unique blockchain https://unique.network
import {Sr25519Account} from '@unique-nft/sr25519'
import Sdk from '@unique-nft/sdk'
import {Address} from '@unique-nft/utils'
export const getLinkToCollection = (sdk: Sdk, collectionId: number) => {
return `${sdk.options.baseUrl}/collections?collectionId=${collectionId}`
}
export const getLinkToToken = (sdk: Sdk, collectionId: number, tokenId: number) => {
return `${sdk.options.baseUrl}/tokens?collectionId=${collectionId}&tokenId=${tokenId}`
@fend25
fend25 / demo.mts
Last active December 2, 2022 12:02
Brief Unique collection and token creation overview
import {Sdk} from "@unique-nft/sdk";
import {KeyringProvider} from "@unique-nft/accounts/keyring";
import {
AttributeType,
COLLECTION_SCHEMA_NAME,
UniqueCollectionSchemaToCreate,
UniqueTokenToCreate
} from '@unique-nft/schemas'
/*
import {sha256} from '@noble/hashes/sha256'
import {sha512} from '@noble/hashes/sha512'
import {pbkdf2Async} from '@noble/hashes/pbkdf2'
const INVALID_MNEMONIC = 'Invalid mnemonic'
const INVALID_ENTROPY = 'Invalid entropy'
const INVALID_CHECKSUM = 'Invalid mnemonic checksum'
export const DEFAULT_WORDLIST: string = 'abandon|ability|able|about|above|absent|absorb|abstract|absurd|abuse|access|accident|account|accuse|achieve|acid|acoustic|acquire|across|act|action|actor|actress|actual|adapt|add|addict|address|adjust|admit|adult|advance|advice|aerobic|affair|afford|afraid|again|age|agent|agree|ahead|aim|air|airport|aisle|alarm|album|alcohol|alert|alien|all|alley|allow|almost|alone|alpha|already|also|alter|always|amateur|amazing|among|amount|amused|analyst|anchor|ancient|anger|angle|angry|animal|ankle|announce|annual|another|answer|antenna|antique|anxiety|any|apart|apology|appear|apple|approve|april|arch|arctic|area|arena|argue|arm|armed|armor|army|around|arrange|arrest|arrive|arrow|art|artefact|artist|artwork|as
@fend25
fend25 / ERC721.md
Last active December 1, 2022 12:38
Unique ERC721Metadata-compatible specification

Unique ERC721-compatible collections specification.

Collection and token properties.

We don't specify any special requirements for common Unique collections. But ERC721-compatible collections MUST meet these requirements:

  1. Collection's flag erc721metadata MUST be true // getting flags not available in solidity interfaces right now

  2. Collection MAY have property {key: "baseURI", value: "<base URI of the tokens>"}

@fend25
fend25 / read_video_punk.js
Last active July 12, 2022 13:42
Read video punk
const {SchemaTools} = require('@unique-nft/api/schema')
const {ApiPromise, WsProvider} = require('@polkadot/api')
const rpc = require('@unique-nft/opal-testnet-types/definitions').unique.rpc
const WS_ENDPOINT = `wss://opal.unique.network`
const COLLECTION_ID = 28
const TOKEN_ID = 10
const run = async() => {
const api = new ApiPromise({

How to use:

  1. Clone this repo: https://github.com/UniqueNetwork/unique-playgrounds and install deps
  2. Place this file to the playgrounds repo, folder src/playgrounds: src/playgrounds/sadu_mint.dev.js.
  3. Place env file to the playgrounds repo, folder src/playgrounds: src/playgrounds/__env.dev.js.
  4. Place folder with all 24 token JSONs to the folder data/sadu_token_jsons
  5. Check and change config - __env.dev.js. Especially the ceed.
  6. REALLY CAREFULLY check var ACCOUNT_TO_WHERE_TO_MINT in the main file - line 17.
  7. Check collection name and token prefix - remove ${rnd} and change token prefix to 'SADU'
  8. Try to run the script on the DEV Quartz (wss://ws-quartz-dev.comecord.com).
@fend25
fend25 / TypedObjectMethods.ts
Created May 8, 2020 13:29
Typescript. Typed versions of Object.keys, Object.values, Object.entries
export const getKeys = <T extends Object>(o: T) => Object.keys(o) as Array<keyof T>
export const getValues = <T extends Object>(o: T) => Object.values(o) as Array<T[keyof T]>
export const getEntries = <T extends Object>(o: T) => Object.entries(o) as Array<[keyof T, T[keyof T]]>