# Metagraph Tokens

Metagraph tokens work in much the same way as DAG. They share a common transaction format and API interface. Both DAG and metagraph tokens use DAG addresses for their balance maps so a single public/private keypair can control DAG and metagraph token accounts.

**Minimum Version**

You will need version 2.1.1 or higher in order to interact with metagraph token networks.

### Connecting to a metagraph[​](https://docs.constellationnetwork.io/hypergraph/metagraph-tokens#connecting-to-a-metagraph) <a href="#connecting-to-a-metagraph" id="connecting-to-a-metagraph"></a>

In order to interact with a metagraph token you will need to first need to create a connection to the Hypergraph, then create a metagraph client instance to connect to the metagraph and send transactions.

The example below connects to **IntegrationNet**. Fill in `:metagraph-l0-endpoint`, `:metagraph-currency-l1-endpoint`, and `:metagraph-id` in the code below with the correct details for the metagraph you are connecting to.

```typescript
const { dag4 } = require('@stardust-collective/dag4');

// Connect to Hypergraph on IntegrationNet or MainNet
dag4.account.connect({
  networkVersion: '2.0',
  beUrl: "https://be-integrationnet.constellationnetwork.io",
  l0Url: "https://l0-lb-integrationnet.constellationnetwork.io",
  l1Url: "https://l1-lb-integrationnet.constellationnetwork.io",
});

dag4.account.loginPrivateKey('MY-PRIVATE-KEY');

// Create a metagraphClient instance to connect to a specific metagraph
const metagraphClient = dag4.account.createMetagraphTokenClient({
  beUrl: "https://be-integrationnet.constellationnetwork.io",
  l0Url: ':metagraph-l0-endpoint',
  l1Url: ':metagraph-currency-l1-endpoint',
  metagraphId: ':metagraph-id'
});

// Make calls directly to the metagraph (check balance, send transactions, etc.)
await metagraphClient.getBalance();
// 100000
```

#### Metagraph connection details[​](https://docs.constellationnetwork.io/hypergraph/metagraph-tokens#metagraph-connection-details) <a href="#metagraph-connection-details" id="metagraph-connection-details"></a>

A list of existing metagraphs can be found on the [DAG Explorer](https://mainnet.dagexplorer.io/metagraphs). On each metagraph's page you'll find the Metagraph ID, as well as L0 and currency L1 endpoints, which are necessary for configuring your metagraph client to connect to a specific metagraph network.

#### Send a single transaction[​](https://docs.constellationnetwork.io/hypergraph/metagraph-tokens#send-a-single-transaction) <a href="#send-a-single-transaction" id="send-a-single-transaction"></a>

The metagraph client has all the same methods as `dag4.account` except `transferDag` becomes `transfer` and `transferDagBatch` becomes `transferBatch`.

```typescript
// connect as shown above
const toAddress = 'DAGabc123...';
const amount = 25.551;
const fee = 0;

await metagraphClient.transfer(toAddress, amount, fee);
```

#### Generate bulk transactions offline and send[​](https://docs.constellationnetwork.io/hypergraph/metagraph-tokens#generate-bulk-transactions-offline-and-send) <a href="#generate-bulk-transactions-offline-and-send" id="generate-bulk-transactions-offline-and-send"></a>

```typescript
// Get last ref online, or else fetch from an offline data store
let lastRef = await metagraphClient.getAddressLastAcceptedTransactionRef('DAGWalletSendingAddress');

// Generate txns offline
const txn_data = [
  {address: 'DAGabc123...', amount: 10, fee: 0},
  {address: 'DAGxyz987...', amount: 25.01, fee: 0},
  {address: 'DAGzzz555...', amount: 1.01, fee: 0},
  {address: 'DAGwww988...', amount: 0.00000001, fee: 0},
];

const hashes = await metagraphClient.transferBatch(txn_data, lastRef);

// console.log(hashes)
```

**Transaction Fees**

Note that transaction fees on metagraph networks are paid in the network's metagraph token, not in DAG.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.constellationnetwork.io/network-apis/api-reference/dag4.js/metagraph-tokens.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
