Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
GET https://faucet.constellationnetwork.io/integrationnet/faucet/<YOUR WALLET ADDRESS>
const privKey = dag4.keyStore.generatePrivateKey();
const pubKey = dag4.keyStore.getPublicKeyFromPrivate(privateKey);
const signature = await dag4.keyStore.sign(privKey, message);
const verified = dag4.keyStore.verify(pubKey, message, signature);
if (verified) {
console.log('Signature verified');
} else {
console.log('Signature invalid');
}Dag4.js Javascript API
npm install @stardust-collective/dag4yarn add @stardust-collective/dag4const { dag4 } = require('@stardust-collective/dag4');import { dag4 } from '@stardust-collective/dag4';const pk = dag4.keyStore.generatePrivateKey();dag4.account.loginPrivateKey(pk);dag4.account.loginSeedPhrase('disco foxtrot calm appleseed trinity organ putter waldorf ordinary shatter green portion');const address = dag4.account.address;dag4.account.publicKey;

yarn add @stardust-collective/dag4const { dag4 } = require('@stardust-collective/dag4');import { dag4 } from '@stardust-collective/dag4';dag4.account.connect({
networkVersion: '2.0',
testnet: true
});dag4.account.connect({
networkVersion: '2.0',
beUrl: 'https://be-mainnet.constellationnetwork.io/',
l0Url: 'http://13.52.246.74:9000',
l1Url: 'http://13.52.246.74:9010'
});dag4.account.connect({
id: 'integration2',
networkVersion: '2.0',
beUrl: 'https://be-integrationnet.constellationnetwork.io',
l0Url: 'https://l0-lb-integrationnet.constellationnetwork.io',
l1Url: 'https://l1-lb-integrationnet.constellationnetwork.io'
}, false);dag4.account.connect({
networkVersion: '2.0',
testnet: false
});dag4.account.connect({
networkVersion: '2.0',
testnet: true
});const { dag4 } = require('@stardust-collective/dag4');
dag4.account.connect({
networkVersion: '2.0',
testnet: true
});
dag4.account.loginPrivateKey('MY-PRIVATE-KEY');
const toAddress = 'DAGabc123...';
const amount = 25.551;
const fee = 0;
await dag4.account.transferDag(toAddress, amount, fee);// Get last ref online, or else fetch from an offline data store
const lastRef = await dag4.network.getAddressLastAcceptedTransactionRef('DAGWalletSendingAddress');
// Get signed transaction (offline)
const txn = await dag4.account.generateSignedTransaction('DAGabc123...', 25.551, 0, lastRef);
// Send transaction (online)
await dag4.network.postTransaction(txn);// Get last ref online, or else fetch from an offline data store
let lastRef = await dag4.network.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 dag4.account.transferDagBatch(txn_data, lastRef);
// console.log(hashes)// Send transaction
const hash = await dag4.network.postTransaction(txn);
// Keep checking the transaction status until this returns null
const pendingTx = await dag4.network.getPendingTransaction(txHash);
// Check the block explore API
if (pendingTx === null) {
const confirmedTx = await dag4.network.getTransaction(txHash);
if (confirmedTx) {
// Txn is confirmed - from this point the state cannot be changed
console.log('Transaction confirmed');
} else {
// The txn cannot be found on block explorer. It's a good idea to wait several seconds and try again to confirm the txn has actually been dropped
console.log('Transaction dropped - not confirmed');
}
}{
"value": {
// Transaction body containing all transaction details
},
"proofs": [
{
"id": "<signer public key>",
"signature": "<signature of transaction body>"
}
]
}function kryoSerialize(encodedTransaction):
prefix = "03" + utf8EncodedLength(encodedTransaction.length + 1)
hexTransaction = hexEncode(utf8Encode(encodedTransaction))
return prefix + hexTransactiontransactionHash = sha256(Buffer.from(serializedTransaction, 'hex'))sha512Hash = sha512(transactionHash)
signature = secp256k1Sign(sha512Hash, privateKey)
hexSignature = signature.toHex()isValid = secp256k1Verify(signature, sha512Hash, publicKey)normalizedBody = normalizeObject(transactionBody)normalizedJson = JSON.stringify(normalizedBody)
utf8Bytes = utf8Encode(normalizedJson)
compressedData = brotliCompress(utf8Bytes, compressionLevel=2)messageHash = sha256(compressedData)sha512Hash = sha512(messageHash)
signature = secp256k1Sign(sha512Hash, privateKey)
hexSignature = signature.toHex(){
"value": normalizedBody,
"proofs": [
{
"id": publicKey,
"signature": hexSignature
}
]
}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// connect as shown above
const toAddress = 'DAGabc123...';
const amount = 25.551;
const fee = 0;
await metagraphClient.transfer(toAddress, amount, fee);// 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)curl -X GET "{GL0_API}/node-params" -H "Content-Type: application/json"curl -X GET "{DAGL1_API}/token-locks/{address}/last-reference" -H "Content-Type: application/json"curl -X POST "{DAGL1_API}/token-locks" -H "Content-Type: application/json" -d '{
"value": {
"source": "DAG4xPWQj3BpAg2YKg3kbdW2AJcMfZz2SUKqYb1t",
"amount": 100000000,
"fee": 0,
"parent": {YOUR_PARENT_REFERENCE},
"currencyId": null,
"unlockEpoch": null
},
"proofs":[{
"id": "c7f9a08bdea7ff5f51c8af16e223a1d751bac9c541125d9aef5658e9b7597aee8cba374119ebe83fb9edd8c0b4654af273f2d052e2d7dd5c6160b6d6c284a17c",
"signature": "3045022017607e6f32295b0ba73b372e31780bd373322b6342c3d234b77bea46adc78dde022100e6ffe2bca011f4850b7c76d549f6768b88d0f4c09745c6567bbbe45983a28bf1"
}]
}'import { dag4 } from '@stardust-collective/dag4'
dag4.account.loginSeedPhrase(YOUR_SEED_PHRASE)
dag4.account.connect({
networkVersion: '2.0',
l0Url: {GL0_API},
l1Url: {DAGL1_API}
})
await dag4.account.postTokenLock({
source: dag4.account.address,
amount: 500000000000,
fee: 0,
tokenL1Url: {DAGL1_API},
unlockEpoch: null,
currencyId: null,
})curl -X GET "{GL0_API}/delegated-stakes/{address}/info" -H "Content-Type: application/json"curl -X POST "{GL0_API}/delegated-stakes" -H "Content-Type: application/json" -d '{
"value": {
"source": "{SENDER_ADDRESS}",
"nodeId": "{NODE_ID}",
"amount": 100000000,
"fee": 0,
"tokenLockRef": {TOKEN_LOCK_REF},
"parent": {PARENT_REFERENCE}
},
"proofs":[{
"id": "c7f9a08bdea7ff5f51c8af16e223a1d751bac9c541125d9aef5658e9b7597aee8cba374119ebe83fb9edd8c0b4654af273f2d052e2d7dd5c6160b6d6c284a17c",
"signature": "3045022017607e6f32295b0ba73b372e31780bd373322b6342c3d234b77bea46adc78dde022100e6ffe2bca011f4850b7c76d549f6768b88d0f4c09745c6567bbbe45983a28bf1"
}]
}'import { dag4 } from '@stardust-collective/dag4'
dag4.account.loginSeedPhrase(YOUR_SEED_PHRASE)
dag4.account.connect({
networkVersion: '2.0',
l0Url: {GL0_API},
l1Url: {DAGL1_API}
})
await dag4.account.postDelegatedStake({
source: dag4.account.address,
nodeId: "{NODE_ID}",
amount: 500000000000,
fee: 0,
tokenLockRef: "{TOKEN_LOCK_REF}"
})curl -X GET "{GL0_API}/delegated-stakes/{address}/info" -H "Content-Type: application/json"curl -X GET "{GL0_API}/node-params" -H "Content-Type: application/json"curl -X POST "{GL0_API}/delegated-stakes" -H "Content-Type: application/json" -d '{
"value": {
"source": "{SENDER_ADDRESS}",
"nodeId": "{NEW_NODE_ID}",
"amount": 100000000,
"fee": 0,
"tokenLockRef": {TOKEN_LOCK_REF},
"parent": {PARENT_REFERENCE}
},
"proofs":[{
"id": "c7f9a08bdea7ff5f51c8af16e223a1d751bac9c541125d9aef5658e9b7597aee8cba374119ebe83fb9edd8c0b4654af273f2d052e2d7dd5c6160b6d6c284a17c",
"signature": "3045022017607e6f32295b0ba73b372e31780bd373322b6342c3d234b77bea46adc78dde022100e6ffe2bca011f4850b7c76d549f6768b88d0f4c09745c6567bbbe45983a28bf1"
}]
}'import { dag4 } from '@stardust-collective/dag4'
dag4.account.loginSeedPhrase(YOUR_SEED_PHRASE)
dag4.account.connect({
networkVersion: '2.0',
l0Url: {GL0_API},
l1Url: {DAGL1_API}
})
await dag4.account.postDelegatedStake({
source: dag4.account.address,
nodeId: "{NEW_NODE_ID}",
amount: 500000000000,
fee: 0,
tokenLockRef: "{TOKEN_LOCK_REF}"
})curl -X GET "{GL0_API}/delegated-stakes/{address}/info" -H "Content-Type: application/json"curl -X PUT "{GL0_API}/delegated-stakes" -H "Content-Type: application/json" -d '{
"source": "{SENDER_ADDRESS}",
"stakeRef": "{DELEGATED_STAKE_REFERENCE}"
}'dag4.account.loginSeedPhrase(YOUR_SEED_PHRASE)
dag4.account.connect({
networkVersion: '2.0',
l0Url: {GL0_API},
l1Url: {DAGL1_API}
})
await dag4.account.putWithdrawDelegatedStake({
source: dag4.account.address,
stakeRef: "{DELEGATED_STAKE_REFERENCE}"
})curl -X GET "{GL0_API}/delegated-stakes/{address}/info" -H "Content-Type: application/json"