import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import TOCInline from '@theme/TOCInline';

# Storing Data

<TOCInline
  maxHeadingLevel={4}
  toc={toc}
/>

## Overview

When storing data, the top-level property must match an account ID. All the nested objects/properties will then be stored under this account.

:::note

The signer account **MUST** have write permissions granted for the account to which it wants to write. See [granting permissions](granting-permissions) on how to grant write permissions.

:::

:::note

The signer account automatically has write permissions for their own account.

:::

## Storing data for an account

<Tabs
  defaultValue="javascript-via-package-manager"
  values={[
    { label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
    { label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
    { label: 'TypeScript', value: 'typescript' },
  ]}>
  <TabItem value="javascript-via-package-manager">

    ```js
    const { Social } = require('@builddao/near-social-js');

    const social = new Social();
    const transaction = await social.set({
      account: {
        accountID: 'alice.near',
        publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
      },
      data: {
        ['alice.near']: {
          profile: {
            name: 'Alice',
          },
        },
      },
    });

    // ...sign the returned transaction and post to the network
    ```

  </TabItem>
  <TabItem value="javascript-via-cdn">

    ```js
    var social = new NEARSocialSDK();

    social.set({
      account: {
        accountID: 'alice.near',
        publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
      },
      data: {
        ['alice.near']: {
          profile: {
            name: 'Alice'
          }
        }
      }
    })
    .then((transaction) => {
      // ...sign the returned transaction and post to the network
    });
    ```

  </TabItem>
  <TabItem value="typescript">

    ```typescript
    import { Social } from '@builddao/near-social-js';

    const social = new Social();
    const transaction = await social.set({
      account: {
        accountID: 'alice.near',
        publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
      },
      data: {
        ['alice.near']: {
          profile: {
            name: 'Alice',
          },
        },
      },
    });

    // ...sign the returned transaction and post to the network
    ```

  </TabItem>
</Tabs>

