Getting cTRNG via IPFS Beacon
The IPFS beacon provides public access to cTRNG values without requiring any authentication or API credentials. The beacon is updated every 60 seconds with new cosmic random number data.
Overview
The IPFS beacon is a decentralized way to access cTRNG values published to IPFS. Unlike the Orbitport API, this method requires no credentials and is completely public. However, the data is updated at a fixed interval of 60 seconds, so it may not be as real-time as the API method.
IPFS Beacon URL
The public IPFS beacon is available at:
https://ipfs.io/ipns/k2k4r8lvomw737sajfnpav0dpeernugnryng50uheyk1k39lursmn09f
Data Structure
The IPFS beacon returns data in a different format than the Orbitport API. Each response contains:
{
"previous": "/ipfs/bafkreial7oeangta7hakknhzsjzja4k2sehnsykx2u7bm6wdz46ug42me4",
"data": {
"sequence": 87963,
"timestamp": 1769179239,
"ctrng": [
"88943046891c6c971f185c7cd69a350d850fca480facf549777efc4602ec94a6",
"802a5afa3b09c360ec56cbe67cb615e038f307c905d199993e28ce38c21e9108",
"dbbe94501ed32c55acb4ad4512da0c3871f497930c4d2d9061bbe7bd634458fc"
]
}
}
Fields
previous: The Content Identifier (CID) of the previous block in the chain. This allows you to traverse back through historical data.data.sequence: The sequence number of this block.data.timestamp: Unix timestamp when this block was created.data.ctrng: An array of cTRNG values. Currently contains 3 values, but this can be more in the future.
Fetching from IPFS
Using curl
curl https://ipfs.io/ipns/k2k4r8lvomw737sajfnpav0dpeernugnryng50uheyk1k39lursmn09f
Using JavaScript/TypeScript
async function fetchCTRNGFromIPFS() {
const response = await fetch(
'https://ipfs.io/ipns/k2k4r8lvomw737sajfnpav0dpeernugnryng50uheyk1k39lursmn09f'
);
const data = await response.json();
console.log('Sequence:', data.data.sequence);
console.log('Timestamp:', data.data.timestamp);
console.log('cTRNG values:', data.data.ctrng);
// Access a specific cTRNG value (e.g., first one)
const firstCTRNG = data.data.ctrng[0];
return firstCTRNG;
}
Using Node.js
const https = require('https');
function fetchCTRNGFromIPFS() {
return new Promise((resolve, reject) => {
https.get(
'https://ipfs.io/ipns/k2k4r8lvomw737sajfnpav0dpeernugnryng50uheyk1k39lursmn09f',
(res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
const json = JSON.parse(data);
resolve(json);
});
}
).on('error', reject);
});
}
// Usage
fetchCTRNGFromIPFS().then((result) => {
console.log('cTRNG values:', result.data.ctrng);
});
Traversing Historical Data
The previous field in each response contains the CID of the previous block, creating a chain of historical data. You can traverse back through this chain to access older cTRNG values.
Example: Fetching Previous Block
async function fetchPreviousBlock(currentData: any) {
if (!currentData.previous) {
return null;
}
// Extract CID from the previous field
// Format: "/ipfs/bafkreial7oeangta7hakknhzsjzja4k2sehnsykx2u7bm6wdz46ug42me4"
const cid = currentData.previous.replace('/ipfs/', '');
const response = await fetch(`https://ipfs.io/ipfs/${cid}`);
const previousData = await response.json();
return previousData;
}
// Usage: Traverse back through blocks
async function traverseBlocks(blocks: number) {
let current = await fetchCTRNGFromIPFS();
const history = [current];
for (let i = 0; i < blocks && current.previous; i++) {
current = await fetchPreviousBlock(current);
if (current) {
history.push(current);
}
}
return history;
}
Update Frequency
The IPFS beacon is updated every 60 seconds with new cTRNG values. This means:
- The data you fetch may be up to 60 seconds old
- For real-time requirements, consider using the Orbitport API or Orbitport SDK
- The beacon provides a reliable, decentralized source of randomness without authentication
Array Size
The ctrng array currently contains 3 values, but this can be more in the future. When accessing the array:
- Always check the array length before accessing specific indices
- Use array methods like
map,filter, orforEachto process all values - Don't assume a fixed array size in your code
Example: Processing All cTRNG Values
async function processAllCTRNGValues() {
const data = await fetchCTRNGFromIPFS();
const ctrngValues = data.data.ctrng;
// Process all values regardless of array size
ctrngValues.forEach((value, index) => {
console.log(`cTRNG ${index}: ${value}`);
// Use the value for your application
});
return ctrngValues;
}
Use Cases
The IPFS beacon method is ideal for:
- Applications that don't require real-time randomness
- Public projects that want to avoid API authentication
- Decentralized applications that prefer IPFS-based data sources
- Applications that need to verify historical randomness data
- Projects that want to reduce dependencies on centralized APIs
Next Steps
- For authenticated, real-time access: See Using Orbitport API
- For a TypeScript SDK with automatic fallback: See Using Orbitport SDK