Skip to main content

Metagraph Tokens

Metagraph tokens work in much the same way as DAG. In order to interact with a metagraph token you will need to first create a metagraph client.

Minimum Version

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

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

dag4.account.connect({
networkVersion: '2.0',
testnet: true
});

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

const metagraphClient = dag4.account.createMetagraphTokenClient({
l0Url: 'http://metagraph-l0.example.com',
l1Url: 'http://metagraph-l1.example.com'
});


await metagraphClient.getBalance();
// 100000

Send a single transaction

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

// 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

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

// Generate txns offline
const txn_data = [
{to: 'DAGabc123...', amount: 10, fee: 0},
{to: 'DAGxyz987...', amount: 25.01, fee: 0},
{to: 'DAGzzz555...', amount: 1.01, fee: 0},
{to: '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.