This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

planter
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

planter

Create Metanet Nodes on Bitcoin SV

planter is a simple library for fetching and creating Metanet nodes on the Bitcoin SV blockchain.

code

Setup

npm i planter

Include planter in your project

import { Planter } from "planter";
<script src="https://unpkg.com/bsv/bsv.min.js"></script>
<script src="https://unpkg.com/planter/dist/planter.min.js"></script>

Be sure to include the bsv library as well when using the web version.

Usage

const planter = new Planter();

This will generate a wallet for you which will be used to derive node addresses and sign transactions. You can use an existing wallet by passing an extended private Key inside of the config object.

const planter = new Planter({
  xprivKey:
    "xprv9s21ZrQH143K3eQCpBqZiuLgNSFPAfkqimfqyDxJ6HAaVUqWWJ4vz7eZdhgkR66jD1a2BtQEXbYjjbfVXWhxz7g4sNujBt6cnAoJrdfLkHh"
});

Accepted config options are

  • xprivKey: string - An extended private Key from which the wallet and nodes are generated.
  • feeb: number - Fee per byte. Default is 1.4
  • nodeInterface - The instance of an implementation of a NodeInterface. Implementations exist in src/node-interfaces/.

By default, the Bitindex API is used for pushing transactions and fetching UTXOs. An Implementation for the newer MatterCloud API exists as well. New MatterCloud instances can be passed an API key, alternatively a new one is automatically requested.

import { Mattercloud } from "planter/lib/node-interfaces/mattercloud";
 
const planter = new Planter({
  nodeInterface: new Mattercloud({
    apiKey: "198t2pusaKhaqHSRsfQBtfyE2XR8Xe7Wsd"
  })
});

Funding can be provided by depositing BSV to the associated address.

planter.fundingAddress;

Creating nodes

await planter.createNode(options);

These additional options can be passed:

  • data: string[] - Array of data to include in OP_RETURN
  • parentTxID: string - For creating child nodes.
  • parentKeyPath: string - Can be passed when parentTxID is also passed to override keyPath of parent node.
  • keyPath: string - For setting the keypath manually. Default is m/0.
  • safe: boolean - Use OP_FALSE for scripts. Default is true.
  • includeKeyPath: boolean - Write keyPath information to OP_RETURN. Defaults to true. Can be deactivated to manage keyPaths locally.

Successfully creating nodes returns an object that contains the new nodes address, id, txid and used keyPath.

Traversing the Metanet

await planter.findAllNodes();

This will query all nodes owned by the Planter instance.

planter is built on top of TreeHugger and exposes its API for querying and traversing metanet nodes. See TreeHuggers Github page for details.

planter also exposes TreeHugger directly for general node querying.

import { TreeHugger } from "planter";
 
const node = await TreeHugger.findNodeByTxid(txid);

Queries

await planter.findSingleNode(query);
await planter.findAllNodes(query);
 
await planter.findNodeById(id);
await planter.findNodeByTxid(txid);
await planter.findNodesByAddress(address);
await planter.findNodesByParentId(id);
await planter.findNodeAndDescendants(id);

Relative traversal

await node.root();
await node.parent();
await node.ancestors();
await node.siblings();
await node.children();
await node.descendants();
await node.selfAndAncestors();
await node.selfAndSiblings();
await node.selfAndChildren();
await node.selfAndDescendants();

Creating child nodes and updates

await node.createChild(planter, options);
await node.createUpdate(planter, options);

The same options as before are accepted. Additionally, the Planter instance that should be used has to be passed.

Node properties

node.keyPath; // extracts keyPath out of OP_RETURN if it exists. Rerturns undefined otherwise
 
// Properties inherited from Treehugger
node.id; // Metanet node id
node.txid; // Transaction id
node.address; // Metanet node address
 
node.isRoot;
node.isChild;
node.isLeaf;
 
node.tx; // Planaria tx object
 
node.inputs; // Shortcut to node.tx.in
node.outputs; // Shortcut to node.tx.out
node.opReturn; // Shortcut to the OP_RETURN output object

Under the hood

planter randomly generates the keypaths used to derive node addresses to avoid accidental reuse and writes them onto the OP_RETURN data right after the metanet protocol keywords.

Package Sidebar

Install

npm i planter

Weekly Downloads

11

Version

0.4.0

License

MIT

Unpacked Size

108 kB

Total Files

24

Last publish

Collaborators

  • merlinb