Skip to main content

🔤 Text/JSON

Upload plain text or JSON strings to Walrus on Lighthouse. For JSON, stringify the object before uploading.

info

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

import lighthouse from '@lighthouse-web3/sdk'

const text = 'Sometimes, I Wish I Was A Cloud, Just Floating Along'
const apiKey = 'YOUR_API_KEY'
const name = 'shikamaru' // Optional

const response = await lighthouse.uploadText(text, apiKey, name, {
storageType: 'walrus',
})

console.log(response)
// Sample response
// {
// data: {
// Name: 'shikamaru',
// Hash: 'QmY77L7JzF8E7Rio4XboEpXL2kTZnW2oBFdzm6c53g5ay8',
// Size: '91'
// }
// }

Upload JSON:

import lighthouse from '@lighthouse-web3/sdk'

const payload = { greeting: 'hello', network: 'walrus' }
const apiKey = 'YOUR_API_KEY'

const response = await lighthouse.uploadText(
JSON.stringify(payload),
apiKey,
'config.json',
{
storageType: 'walrus',
}
)

console.log(response.data.Hash)
info

The name parameter is optional. If omitted, the Name field in the response defaults to the file hash (CID).