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

@ark-project/core

v1.1.4

Published

The ArkChain SDK is a comprehensive TypeScript/JavaScript library designed to interact with the ArkChain orderbook. It simplifies the process of performing various blockchain operations such as creating accounts, listings, offers, and more.

Downloads

442

Readme

ArkChain SDK Library

The ArkChain SDK is a comprehensive TypeScript/JavaScript library designed to interact with the ArkChain orderbook. It simplifies the process of performing various blockchain operations such as creating accounts, listings, offers, and more.

Features

  • Account Creation (Burner Wallets)
  • Listing Creation
  • Offer Creation
  • Order Cancellation
  • Fulfilling Listings and Offers

Installation

npm install @arkproject/core

Development

install dependencies

pnpm install

Running tests

pnpm run test

Running examples

npx ts-node examples/createAccount.ts
npx ts-node examples/createListing.ts
npx ts-node examples/createOffer.ts
npx ts-node examples/cancelListing.ts
npx ts-node examples/fulfillListing.ts
npx ts-node examples/fulfillOffer.ts

Usage

Creating an Account

To create a new account, initialize the RpcProvider with the ArkChain node URL, and then use the createAccount function. This will return an object containing the account details.

import { createAccount } from "arkchain-sdk";
import { RpcProvider } from "starknet";

const provider = new RpcProvider({
  nodeUrl: "http://0.0.0.0:7777"
});

async function createNewAccount() {
  const { account } = await createAccount(provider);
  // Use the account object as needed
}

createNewAccount();

Creating a Listing

To create a listing on the ArkChain, initialize the RpcProvider, create an account, and then use the createListing function with the specified order details.

import { createAccount, createListing } from "arkchain-sdk";
import { ListingV1 } from "arkchain-sdk/types";
import { RpcProvider } from "starknet";

const provider = new RpcProvider({
  nodeUrl: "http://0.0.0.0:7777"
});

async function createNewListing() {
  // Create a new account using the provider
  const { account } = await createAccount(provider);

  // Define the order details
  let order: ListingV1 = {
    brokerId: 123, // The broker ID
    tokenAddress:
      "0x01435498bf393da86b4733b9264a86b58a42b31f8d8b8ba309593e5c17847672", // The token address
    tokenId: 909, // The ID of the token
    startAmount: 600000000000000000 // The starting amount for the order
  };

  // Create the listing on the blockchain using the order details
  await createListing(provider, account, order);
}

createNewListing();

Creating an Offer

To create an offer on the ArkChain, you'll need to initialize the RpcProvider, create an account, and then use the createOffer function with your offer details.

import { createAccount, createOffer } from "arkchain-sdk";
import { OfferV1 } from "arkchain-sdk/types";
import { RpcProvider } from "starknet";

const provider = new RpcProvider({
  nodeUrl: "http://0.0.0.0:7777"
});

async function createNewOffer() {
  // Create a new account using the provider
  const { account } = await createAccount(provider);

  // Define the order details
  let order: OfferV1 = {
    brokerId: 123, // The broker ID
    tokenAddress:
      "0x01435498bf393da86b4733b9264a86b58a42b31f8d8b8ba309593e5c17847672", // The token address
    tokenId: 37, // The ID of the token
    startAmount: 600000000000000000 // The starting amount for the order
  };

  // Create the offer on the blockchain using the order details
  await createOffer(provider, account, order);
}

createNewOffer();

Cancelling an Order

To cancel an order on the ArkChain, use the cancelOrder function with the necessary cancellation details, including the order hash, token address, and token ID. This example assumes that you already have an orderHash from a previously created order and you are using the account that created the listing or the offer.

import { RpcProvider } from "starknet";
import { createAccount, cancelOrder } from "arkchain-sdk";

const provider = new RpcProvider({
  nodeUrl: "http://0.0.0.0:7777"
});

async function cancelExistingOrder(orderHash, tokenAddress, tokenId, account) {
  // Use the account that created the listing or the offer

  // Define the cancel details
  const cancelInfo = {
    order_hash: orderHash,
    token_address: tokenAddress,
    token_id: tokenId
  };

  // Cancel the order
  await cancelOrder(provider, account, cancelInfo);
}

// Example usage (replace with actual orderHash, tokenAddress, tokenId, and account)
const orderHash = "your_order_hash_here";
const tokenAddress = "0x01435498bf393da86b4733b9264a86b58a42b31f8d8b8ba309593e5c17847672";
const tokenId = 6;
const account = /* account object from createAccount or similar method */;

cancelExistingOrder(orderHash, tokenAddress, tokenId, account);

Fulfilling a Listing

To fulfill a listing on the ArkChain, use the fulfillListing function with the necessary details, including the order hash, token address, and token ID. This example assumes that you already have an orderHash from a previously created listing and you are using a separate account to fulfill it.

import { RpcProvider } from "starknet";
import { createAccount, fulfillListing } from "arkchain-sdk";

const provider = new RpcProvider({
  nodeUrl: "http://0.0.0.0:7777"
});

async function fulfillExistingListing(orderHash, tokenAddress, tokenId, fulfillerAccount) {
  // Use a separate account to fulfill the listing
  // The fulfillerAccount should be different from the listing creator's account

  // Define the fulfill details
  const fulfillInfo = {
    order_hash: orderHash,
    token_address: tokenAddress,
    token_id: tokenId
  };

  // Fulfill the listing
  await fulfillListing(provider, fulfillerAccount, fulfillInfo);
}

// Example usage (replace with actual orderHash, tokenAddress, tokenId, and fulfillerAccount)
const orderHash = "your_order_hash_here";
const tokenAddress = "0x01435498bf393da86b4733b9264a86b58a42b31f8d8b8ba309593e5c17847672";
const tokenId = 16;
const fulfillerAccount = /* account object from createAccount or similar method */;

fulfillExistingListing(orderHash, tokenAddress, tokenId, fulfillerAccount);

Fulfilling an Offer

To fulfill an offer on the ArkChain, the original owner of the listing must use the fulfillOffer function. This function requires details including the order hash, token address, and token ID. This example assumes that you have an orderHash from a previously created offer and that you are the original owner of the listing.

import { RpcProvider } from "starknet";
import { createAccount, fulfillOffer } from "arkchain-sdk";

const provider = new RpcProvider({
  nodeUrl: "http://0.0.0.0:7777"
});

async function fulfillExistingOffer(orderHash, tokenAddress, tokenId, ownerAccount) {
  // Ensure the ownerAccount is the original owner of the listing

  // Define the fulfill details
  const fulfillInfo = {
    order_hash: orderHash,
    token_address: tokenAddress,
    token_id: tokenId
  };

  // Fulfill the offer as the original owner
  await fulfillOffer(provider, ownerAccount, fulfillInfo);
}

// Example usage (replace with actual orderHash, tokenAddress, tokenId, and ownerAccount)
const orderHash = "your_order_hash_here";
const tokenAddress = "0x01435498bf393da86b4733b9264a86b58a42b31f8d8b8ba309593e5c17847672";
const tokenId = 36;
const ownerAccount = /* account object of the listing's original owner */;

fulfillExistingOffer(orderHash, tokenAddress, tokenId, ownerAccount);