Skip to content

Latest commit

 

History

History
63 lines (56 loc) · 1.48 KB

share-file.md

File metadata and controls

63 lines (56 loc) · 1.48 KB
layout
title description tableOfContents outline pagination
visible
true
visible
visible
true
visible
true
visible
true

👯 Share File

The owner of the file can share an encrypted file to any other wallet address, this code example demonstrates the same.

{% tabs %} {% tab title="JS SDK" %}

const shareFile = async () => {
  try {
    // CID of the encrypted file that you want to share
    // CID is generated by uploading a file with encryption
    // Only the owner of the file can share it with another wallet address
    const cid = 'YOUR_CID' // Example: "Qma7Na9sEdeM6aQeu6bUFW54HktNnW2k8g226VunXBhrn7";
    const publicKey = 'YOUR_PUBLIC_KEY' // Example: "0xa3c960b3ba29367ecbcaf1430452c6cd7516f588";
    const signedMessage = "SIGNATURE/JWT"
    const publicKeyUserB = ["RECEIVER_PUBLIC_KEY"] //Example: 0x487fc2fE07c593EAb555729c3DD6dF85020B5160

    const shareResponse = await lighthouse.shareFile(
      publicKey,
      publicKeyUserB,
      cid,
      signedMessage
    )

    console.log(shareResponse)
    /* Sample Response
      {
        data: {
          cid: 'QmTsC1UxihvZYBcrA36DGpikiyR8ShosCcygKojHVdjpGd',
          shareTo: [ '0x487fc2fE07c593EAb555729c3DD6dF85020B5160' ],
          status: 'Success'
        }
      }
    */
  } catch (error) {
    console.log(error)
  }
}

shareFile()

{% endtab %}

{% tab title="CLI" %}

lighthouse-web3 share-file [cid] [address]

{% endtab %} {% endtabs %}