Create Metanet Nodes on Bitcoin SV
planter is a simple library for fetching and creating Metanet nodes on the Bitcoin SV blockchain.
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.
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 is1.4
nodeInterface
- The instance of an implementation of aNodeInterface
. Implementations exist insrc/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;
await planter.createNode(options);
These additional options can be passed:
data: string[]
- Array of data to include inOP_RETURN
parentTxID: string
- For creating child nodes.parentKeyPath: string
- Can be passed whenparentTxID
is also passed to overridekeyPath
of parent node.keyPath: string
- For setting the keypath manually. Default ism/0
.safe: boolean
- Use OP_FALSE for scripts. Default istrue
.includeKeyPath: boolean
- WritekeyPath
information toOP_RETURN
. Defaults totrue
. Can be deactivated to manage keyPaths locally.
Successfully creating nodes returns an object that contains the new nodes address
, id
, txid
and used keyPath
.
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);
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);
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();
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.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
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.