đ¤ 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.
- JS SDK
- API
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).
Upload text by sending it as a file to the Walrus add endpoint:
echo 'Sometimes, I Wish I Was A Cloud, Just Floating Along' | curl -X POST \
-H 'Authorization: Bearer API_KEY' \
-F 'file=@-;filename=shikamaru.txt' \
'https://upload-walrus.lighthouse.storage/api/v0/add?storageType=walrus'
For JSON, write the string to a temp file or pipe JSON.stringify output the same way. storageType must be set to walrus.