Skip to main content

📁 File

Upload any file to Walrus on Lighthouse. Files are stored on Walrus and indexed with an IPFS-compatible CID.

info

You need a Walrus API key created with your Sui address before uploading.

Node.js:

import lighthouse from '@lighthouse-web3/sdk'

/**
* Upload a file or folder to Walrus on Lighthouse.
*
* @param {string} path - Location of your file or folder.
* @param {string} apiKey - Your Lighthouse API key.
* @param {object} options - Must include storageType: `"walrus"`.
*/
const uploadResponse = await lighthouse.upload(
'/home/cosmos/Desktop/wow.jpg',
'YOUR_API_KEY_HERE',
{
storageType: 'walrus',
}
)

console.log(uploadResponse)

/* Sample response
{
data: {
Name: 'wow.jpg',
Hash: 'QmUHDKv3NNL1mrg4NTW4WwJqetzwZbGNitdjr2G6Z5Xe6s',
Size: '31735'
}
}
*/

With progress tracking:

import lighthouse from '@lighthouse-web3/sdk'

const uploadWithOptions = async () => {
const response = await lighthouse.upload(
'/home/cosmos/Desktop/wow.jpg',
'YOUR_API_KEY_HERE',
{
storageType: 'walrus',
cidVersion: 1,
onProgress: (progressData) => {
console.log(`Upload Progress: ${progressData.progress}%`)
},
}
)

console.log('File uploaded:', response.data.Hash)
console.log('Visit at https://gateway-walrus.lighthouse.storage/ipfs/' + response.data.Hash)
}

Browser:

import React from 'react'
import lighthouse from '@lighthouse-web3/sdk'

function App() {
const uploadFile = async (file) => {
const output = await lighthouse.upload(file, 'YOUR_API_KEY', {
storageType: 'walrus',
onProgress: (progressData) => {
console.log(`Upload Progress: ${progressData.progress}%`)
},
})

console.log('File Status:', output)
console.log('Visit at https://gateway-walrus.lighthouse.storage/ipfs/' + output.data.Hash)
}

return (
<div className="App">
<input onChange={(e) => uploadFile(e.target.files[0])} type="file" />
</div>
)
}

export default App