npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@oxheadalpha/tezos-tools

v10.1.0

Published

TypeScript API for LIGO, Flextesa, IPFS helper tools

Downloads

46

Readme

Description

TypeScript API for

  • LIGO contract compilation.

  • Interaction with Flextesa sandbox (using docker images).

  • Pinning files and directories to Pinata IPFS.

  • Generate Tezos keys.

Scripts

start-sandbox starts Flextesa sandbox.

Example:

$ yarn start-sandbox

kill-sandbox kills running Flextesa sandbox.

Example:

$ yarn kill-sandbox

compile-contract <source_ligo_file> <entry_points_function> <output_michelson_file> compiles a ligo contract to Michelson. This script is an equivalent of ligo compile contract <source_ligo_file> -e <entry_points_function> -o <output_michelson_file>.

Example:

$ yarn compile-contract ligo/examples/fa2_asset_use_example.mligo  asset_main fa2_asset.tz

gen-keys generates a pair of a new secret key and public key hash (tz address).

Example:

$ yarn gen-keys
{
  pkh: 'tz1cxxQ75tknhruvyweB1tndLD4r1EkvCfMA',
  secret: 'edsk3gCeSu8F1vGuJYWrxHCN2nvYgSn3wTRJmFSwG1TgWSEJWrCLv4'
}

API

Ligo

/**
 * Create Ligo compiler API
 * @param cwd working directory to run Ligo commands
 * @returns Ligo object with Typescript API for Ligo compiler
 */
function ligo(cwd?: string): Ligo
/**
 * TypeScript interface to Ligo commands
 */
export interface Ligo {
  /**
   * Compile contract from Ligo language to Michelson
   * @param srcFile path to the contract source file
   * @param main name of the main entry point function for the contract
   * @param dstFile path to the compiled contract resulting file
   */
  compileContract(
    srcFile: string,
    main: string,
    dstFile: string
  ): Promise<void>;
  /**
   * Compile contract from Ligo language to Michelson and loads Michelson code
   * @param srcFile path to the contract source file
   * @param main name of the main entry point function for the contract
   * @param dstFile path to the compiled contract resulting file
   * @returns compiled Michelson code of the contract
   */
  compileAndLoadContract(
    srcFile: string,
    main: string,
    dstFile: string
  ): Promise<string>;
  /**
   * Print to console current Ligo compiler version
   */
  printLigoVersion(): Promise<void>;
}

Usage example:

import { ligo } from '@oxheadalpha/tezos-tools';

const main = async () => {
  const ligoEnv = ligo();
  await ligoEnv.printLigoVersion();

  await ligoEnv.compileContract(
    './ligo/src/fa2_nft_asset.mligo',
    'nft_asset_main',
    './dist/fa2_nft_asset.tz'
  );
};

Flextesa

/**
 * Start a new instance of Flextesa sandbox.
 * Sandbox node RPC will be available at 'http://localhost:20000'.
 */
async function startSandbox(): Promise<void>
/**
 * Kill running Flextesa sandbox.
 */
async function killSandbox(): Promise<void> 
/**
 * Await until sandbox (or other node) is bootstrapped and available.
 * @param toolkit - toolkit which connects to sandbox RPC.
 */
async function awaitForSandbox(toolkit: TezosToolkit): Promise<void>

Usage example:

import {
  startSandbox,
  killSandbox,
  awaitForSandbox
} from '@oxheadalpha/tezos-tools';

if (network === 'sandbox') {
  await startSandbox();
  await awaitForNetwork(toolkit);

  await runBlockchainTasks(toolkit);

  await killSandbox();
}

Originate Contract

/**
 * Originate a contract on blockchain
 * @param tz toolkit pointing to a blockchain node RPC. Must be initialized with
 * a signer; Signer will pay origination fees.
 * @param code Michelson code of the contract
 * @param storage initial storage of the contract. Storage can be either Michelson
 * string or TypeScript object
 * @param name name of the contract for logging
 * @returns Taquito contract proxy object
 */
async function originateContract(
  tz: TezosToolkit,
  code: string,
  storage: string | object,
  name: string
): Promise<Contract>

Usage example:

import { originateContract } from '@oxheadalpha/tezos-tools';

const contract = await originateContract(tz, code, storage, 'nft');
return contract.address;

Generate Tezos Keys

/**
 * @param keyType prefix to append to a generated key. The default value is 'edsk2'
 * @returns `{pkh, secret}` where `pkh` if a public key hash (tz address) and
 * `secret` is a secret key.
 */
async function newKeys(): Promise<{pkh, secret}>

Usage example:

  import { newKeys } from '@oxheadalpha/tezos-tools';
  const {pkh, secret} = await newKeys();

Pinata IPFS

/**
 * Pin local file to IPFS using Pinata API
 * @param apiKey Pinata account API key
 * @param secretKey Pinata account secret key
 * @param name pinned file name on IPFS
 * @param filePath path to a local file to be pinned
 * @returns IPFS hash (CID) for a pinned file
 */
async function pinFile(
  apiKey: string,
  secretKey: string,
  name: string,
  filePath: string
): Promise<string>
/**
 * Pin local directory to IPFS using Pinata API
 * @param apiKey Pinata account API key
 * @param secretKey Pinata account secret key
 * @param name pinned directory name on IPFS
 * @param dirPath path to a local directory to be pinned
 * @returns IPFS hash (CID) for a pinned directory
 */
export async function pinDirectory(
  apiKey: string,
  secretKey: string,
  name: string,
  dirPath: string
): Promise<string>

Usage example:

import { pinFile, pinDirectory } from '@oxheadalpha/tezos-tools';

const cid = await pinFile(
  pinataKeys.apiKey,
  pinataKeys.secretKey,
  tag,
  resolvedPath
);

console.log(`ipfs://${cid}`);