Developer API
...
Getting Started
@xandeum/web3.js
7 min
xandeum web3 library v1 12 0 solana transaction builder for interacting with a file system on the xandeum network this package provides a javascript/typescript interface to construct solana transactions for creating, modifying, and managing file systems on chain using the xandeum program ✨ features create and delete file systems ( bigbang , armageddon ) manage files and directories ( create , rename , remove , copy ) read and write file contents with byte level control ( peek , poke ) secure path validation and serialization compatible with @solana/web3 js 📦 installation npm install @xandeum/web3 js or yarn add @xandeum/web3 js 🚀 usage import { bigbang, armageddon, createfile, poke, peek, copypath } from '@xandeum/web3 js' import { connection, sendandconfirmtransaction, keypair, publickey } from '@solana/web3 js' const connection = new connection('https //apis devnet xandeum com) const signer = keypair generate() const wallet = signer publickey async function main() { // create a new file system const tx1 = await bigbang(wallet) await sendandconfirmtransaction(connection, tx1, \[signer]) // create a file const tx2 = await createfile('1', '/','hello txt', wallet) await sendandconfirmtransaction(connection, tx2, \[signer]) const dataaccount = new publickey("fbm4g63kpuneqylwqy6zvu81asmqmkqjsdxngbkq3dkv"); // write data const tx3 = await poke('1', '/hello txt', 0, buffer from('hello xandeum!'), wallet) await sendandconfirmtransaction(connection, tx3, \[signer]) // read data const tx4 = await peek('1', '/hello txt', 0, 14, wallet) await sendandconfirmtransaction(connection, tx4, \[signer]) } 🧩 api overview bigbang(wallet publickey) promise creates a new file system account armageddon(fsid string, wallet publickey) promise deletes a file system by id createfile(fsid string, path string, wallet publickey) promise creates a new file at the given path poke(fsid string, path string, offset number, data buffer, wallet publickey) promise writes bytes to a file starting at a specific offset peek(fsid string, path string, offset number, length number, wallet publickey) promise reads bytes from a file copypath(fsid string, srcpath string, destpath string, wallet publickey) promise copies a file or directory from one path to another other available functions renamepath removefile removedirectory createdirectory exists listdirectoryentry getmetadata all functions that accept a file or directory path will validate inputs using sanitizepath to prevent invalid characters 🌐 websocket subscription subscriberesult(connection connection,tx string, onresult (result resultvalue) => void, onerror? (err any) => void, onclose? () => void) void subscribes to results from a transaction via websocket used for listening events triggered by the transaction parameters connection the solana web3 connection with xandeum compatible json rpc endpoint (e g , 'https //api devnet solana com' ) tx — transaction signature to subscribe to onresult(result) — called when a valid result is received onerror(err) — optional callback for connection errors onclose() — optional callback for connection closure example subscriberesult( connection, 'transactionsignaturehere', result => { console log('result ', result) } ) example import { bigbang, createfile, poke, peek, subscriberesult } from '@xandeum/web3 js' import { connection, sendandconfirmtransaction, keypair } from '@solana/web3 js' const connection = new connection('https //api mainnet beta solana com') const signer = keypair generate() const wallet = signer publickey async function main() { const tx = await createfile('1', '/hello txt', wallet) const txsignature = await sendandconfirmtransaction(connection, tx, \[signer]) subscriberesult( connection, txsignature, result => { console log('received result ', result) }, err => console error('websocket error ', err), () => console log('websocket closed') ) } apache 2 0 © xandeum 👤 author built by xandeum to provide decentralized, programmable file systems on solana via the xandeum protocol