---
# System prepended metadata

title: Web5-js Write Permutations

---

# Web5-js Write Permutations

## Tech Preview at Bitcoin Conf 

For the Web5 Tech Preview launched at Bitcoin Conf Miami:

- when calling `Web5.connect()`, a Web5 instance `web5` and an ION `did` will be returned
- each developer will then have:
  - a `Web5UserAgent` that has an embedded DWN running in-page/browser
  - a `dwn-server` endpoint hosted by TBD that the developer can use and is publicly accessible (e.g., chat app scenario)
  - the ION DID generated includes the endpoint of the `dwn-server` in its DID Document





## Tech Preview at Bitcoin Conf 

For the Web5 Tech Preview launched at Bitcoin Conf Miami:

- when calling `Web5.connect()`, a Web5 instance `web5` and an ION `did` will be returned
- each developer will then have:
  - a `Web5UserAgent` that has an embedded DWN running in-page/browser
  - a `dwn-server` endpoint hosted by TBD that the developer can use and is publicly accessible (e.g., chat app scenario)
  - the ION DID generated includes the endpoint of the `dwn-server` in its DID Document
- `web5.dwn.records.*` usage:
  - the author that signs the record will always be the currently active DID of the `Web5UserAgent` instance such that the `author:` property doesn't need to be specified in every `web5.dwn.*.*` invocation.
  - the records will assumed to be targeted to the tenant of the currently active DID of the `Web5UserAgent` instance unless a `to: did` property is added to the `web5.dwn.*.*` message options
  - specifying `to: bobDid` will indicate that this record's recipient is `bobDid` so that records with encryption enabled will know which public key to use when signing the symmetric encryption keys
  - store to `agent` stores the message/data to the in-page/browser DWN
  - store to `endpoints` stores the message/data to the `dwn-server`
  - store `false` indicates that the message should NOT be persisted to either the in-page/browser DWN nor the TBD hosted `dwn-server`.  This is typically only used in the case where the developer intent is that the record will either NEVER be written to the active DID's datastores OR in the case where writing to the active DID's in-page/browser or `dwn-server` endpoint DWNs should ONLY happen after the initial writes are successful.  Scenario might be: "only write this record to my in-page DWN if the write to Bob's DWN succeeds."
  - calling `record.send(did)` after the initial write will have the effect of transporting the message/data to the service endpoint in the DID document of the specified `did`
  - calling `record.store('agent' | 'endpoint')` will have the effect of writing the message/data to the specified store IF and ONLY IF the earlier writes succeed.  This is done because we'd decided that ordering matters, so the later writes will only occur if the higher precedence writes are successful.  In any event, the developer is in complete control of what to retry and how often to retry.
  - calling `record.store(false)` has no effect and would not make sense.  We can return an error as a convenience to inform the developer that it makes no sense to do this -OR- we can return a 202/success status... but suggestion to return an error so that the NOOP isn't confusing if someone misunderstands what they are requesting.

Query your
const { records } = await web5.dwn.records.query({
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

## All Permutations

1. Your own local
```typescript=
const { record, status } = await web5.dwn.records.write({
  store: 'agent',
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});
```

2. Your own remote
```typescript=
const { record, status } = await web5.dwn.records.write({
  store: 'endpoints',
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});
```

3. Someone else's remote:
```typescript=
const { record, status } = await web5.dwn.records.write({
  to: bobDid,
  store: false,
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});

await record.send(bobDid);
```

4. Your own local + your own remote:
```typescript=
const { record, status } = await web5.dwn.records.write({
  to: bobDid,
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});
```

5. Your own local + someone else's remote:
```typescript=
const { record, status } = await web5.dwn.records.write({
  store: 'agent',
  to: bobDid,
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});

await record.send(bobDid);
```

6. Your own remote + your own local:
```typescript=
const { record } = await web5.dwn.records.write({
  store: 'endpoints',

  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store('agent');
```

7. Your own remote + someone else's remote:
```typescript=
const { record, status } = await web5.dwn.records.write({
  store: 'endpoints',
  to: bobDid,
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});

await record.send(bobDid);
```

8. Someone else's remote + your own local:
```typescript=
const { record, status } = await web5.dwn.records.write({
  store: false,
  to: bobDid,
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});

await record.send(bobDid);
await record.store('agent');
```

9. Someone else's remote + your own remote:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: false,
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.send(bobDid);
await record.store('endpoints');
```

10. Your own local + your own remote + someone else's remote:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: 'agent',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store('endpoints');
await record.send(bobDid);
```

11. Your own local + someone else's remote + your own remote:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: 'agent',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.send(bobDid);
await record.store('endpoints');
```

12. Your own remote + your own local + someone else's remote:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: 'endpoints',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store('agent');
await record.send(bobDid);
```

13. Your own remote + someone else's remote + your own local:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: 'endpoints',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.send(bobDid);
await record.store('agent');
```

14. Someone else's remote + your own local + your own remote:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: false,
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store('agent');
await record.store('endpoints');
```

15. Someone else's remote + your own remote + your own local:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: false,
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store('endpoints');
await record.store('agent');
```

## All Permutations with failure scenarios

#### 1. Your own local
```typescript=
const { record, status } = await web5.dwn.records.write({
  store: 'agent',
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});
```
**Failure Scenarios**

**`Write to your local/agent fails`**
```typescript
// retry
record.store('agent');
```

---

#### 2. Your own remote
```typescript=
const { record, status } = await web5.dwn.records.write({
  store: 'endpoints',
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});
```

**Failure Scenarios**

**`Write to your remote/endpoint(s) all fail`**
```typescript
// retry
record.store('endpoints');
```

---

#### 3. Someone else's remote:
```typescript=
const { record, status } = await web5.dwn.records.write({
  to: bobDid,
  store: false,
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});

await record.send(bobDid);
```

**Failure Scenarios**

**`Write to Bob endpoint(s) all fail`**
```typescript
// retry
record.send(bobDid);
```

---

#### 4. Your own local + your own remote:
```typescript=
const { record, status } = await web5.dwn.records.write({
  to: bobDid,
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});
```

**Failure Scenarios**

**i. `Write to local/agent fails`**
```typescript
// retry local/agents
record.store('agent');
// if write to local/agents succeeds this time, then retry remote/endpoint(s)
record.store('endpoints');
```

**ii. `Write to local/agent succeeds but remote/endpoint(s) all fail`**
```typescript
// retry just remote/endpoint(s)
record.store('endpoints');
```

---

#### 5. Your own local + someone else's remote:
```typescript=
const { record, status } = await web5.dwn.records.write({
  store: 'agent',
  to: bobDid,
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});

await record.send(bobDid);
```

**Failure Scenarios**

**i. `Write to local/agent fails`**
```typescript
// retry local/agents
record.store('agent');
// if write to local/agents succeeds this time, then retry Bob's endpoint(s)
await record.send(bobDid);
```

**ii. `Write to local/agent succeeds but Bob endpoint(s) all fail`**
```typescript
// retry just Bob's endpoint(s)
await record.send(bobDid);
```

---

#### 6. Your own remote + your own local:
```typescript=
const { record } = await web5.dwn.records.write({
  store: 'endpoints',

  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store('agent');
```

**Failure Scenarios**

**i. `Write to your remote/endpoint(s) all fail`**
```typescript
// retry remote/endpoint(s)
record.store('endpoints');
// if write to remote/endpoint(s) succeed this time, then retry local/agent
record.store('agent');
```

**ii. `Write to your remote/endpoint(s) succeeds but local/agent fail`**
```typescript
// retry just local/agent
record.store('agent');
```

---

#### 7. Your own remote + someone else's remote:
```typescript=
const { record, status } = await web5.dwn.records.write({
  store: 'endpoints',
  to: bobDid,
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});

await record.send(bobDid);
```

**Failure Scenarios**

**i. `Write to your remote/endpoint(s) all fail`**
```typescript
// retry remote/endpoint(s)
record.store('endpoints');
// if write to remote/endpoint(s) succeed this time, then retry Bob's endpoint(s)
await record.send(bobDid);
```

**ii. `Write to your remote/endpoint(s) succeeds but Bob endpoint(s) all fail`**
```typescript
// retry just Bob's endpoint(s)
await record.send(bobDid);
```

---

8. Someone else's remote + your own local:
```typescript=
const { record, status } = await web5.dwn.records.write({
  store: false,
  to: bobDid,
  message: {
    "schema": 'whatever'
  },
  data: 'hi'
});

await record.send(bobDid);
await record.store('agent');
```

**Failure Scenarios**

**i. `Write to Bob's endpoint(s) all fail`**
```typescript
// retry Bob's endpoint(s)
await record.send(bobDid);
// if write to Bob's endpoint(s) succeeds this time, then retry local/agent
await record.store('agent');
```

**ii. `Write to Bob's endpoint(s) succeeds but local/agent fails`**
```typescript
// retry just Bob's endpoint(s)
await record.store('agent');
```

---

9. Someone else's remote + your own remote:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: false,
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.send(bobDid);
await record.store('endpoints');
```

**Failure Scenarios**

**i. `Write to Bob's endpoint(s) all fail`**
```typescript
// retry Bob's endpoint(s)
await record.send(bobDid);
// if write to Bob's endpoint(s) succeeds this time, then retry remote/endpoint(s)
await record.store('endpoints');
```

**ii. `Write to Bob's endpoint(s) succeeds but remote/endpoint(s) all fail`**
```typescript
// retry remote/endpoint(s)
await record.store('endpoints');
```

---

10. Your own local + your own remote + someone else's remote:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: 'agent',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store('endpoints');
await record.send(bobDid);
```

**Failure Scenarios**

**i. `Write to local/agent fails`**
```typescript
// retry local/agent first
await record.store('agent');
// if write to local/agent succeeds this time, then retry your remote/endpoint(s)
await record.store('endpoints');
// if write to local/agent and remote/endpoint(s) succeed this time, retry Bob's endpoint(s)
await record.send(bobDid);
```

**ii. `Write to local/agent succeeds but your remote/endpoint(s) all fail`**
```typescript
// retry your remote/endpoint(s)
await record.store('endpoints');
// if write to your remote/endpoint(s) succeed this time, retry Bob's endpoint(s)
await record.send(bobDid);
```

**iii. `Write to local/agent and remote/endpoint(s) succeed but Bob's endpoint(s) all fail`**
```typescript
// retry Bob's endpoint(s)
await record.send(bobDid);
```

---

11. Your own local + someone else's remote + your own remote:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: 'agent',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.send(bobDid);
await record.store('endpoints');
```

**Failure Scenarios**

**i. `Write to local/agent fails`**
```typescript
// retry local/agent first
await record.store('agent');
// if write to local/agent succeeds this time, then retry Bob's endpoint(s)
await record.send(bobDid);
// if write to local/agent and Bob's endpoint(s) succeed this time, retry your remote/endpoint(s)
await record.store('endpoints');

```

**ii. `Write to local/agent succeeds but Bob's endpoint(s) all fail`**
```typescript
// retry Bob's endpoint(s)
await record.send(bobDid);
// if write to Bob's endpoint(s) succeed this time, retry your remote/endpoint(s)
await record.store('endpoints');
```

**iii. `Write to local/agent and Bob's endpoint(s) succeed but your remote/endpoint(s) all fail`**
```typescript
// retry your remote/endpoint(s)
await record.store('endpoints');
```

---

12. Your own remote + your own local + someone else's remote:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: 'endpoints',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store('agent');
await record.send(bobDid);
```

**Failure Scenarios**

**i. `Write to your remote/endpoint(s) all fail`**
```typescript
// retry remote/endpoint(s) first
await record.store('endpoints');
// if write to remote/endpoint(s) succeed this time, then retry your local/agent
await record.store('agent');
// if write to remote/endpoint(s) and your local/agent succeed this time, retry Bob's endpoint(s)
await record.send(bobDid);

```

**ii. `Write to remote/endpoint(s) succeeds but your local/agent fails`**
```typescript
// retry your local/agent
await record.store('agent');
// if write to your local/agent succeed this time, retry Bob's endpoint(s)
await record.send(bobDid);
```

**iii. `Write to remote/endpoint(s) and local/agent succeeds, but Bob's endpoint(s) all fail`**
```typescript
// retry Bob's endpoint(s)
await record.send(bobDid);
```

---

13. Your own remote + someone else's remote + your own local:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: 'endpoints',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.send(bobDid);
await record.store('agent');
```

**Failure Scenarios**

**i. `Write to your remote/endpoint(s) all fail`**
```typescript
// retry remote/endpoint(s) first
await record.store('endpoints');
// if write to remote/endpoint(s) succeed this time, then retry Bob's endpoint(s)
await record.send(bobDid);
// if write to remote/endpoint(s) and Bob's endpoint(s) succeed this time, retry your local/agent
await record.store('agent');
```

**ii. `Write to your remote/endpoint(s) succeeds but Bob's endpoint(s) all fail`**
```typescript
// retry Bob's endpoint(s)
await record.send(bobDid);
// if write to Bob's endpoint(s) succeed this time, retry your local/agent
await record.store('agent');
```

**iii. `Write to remote/endpoint(s) and Bob's endpoint(s) succeed, but local/agent fails`**
```typescript
// retry your local/agent
await record.store('agent');
```

---

14. Someone else's remote + your own local + your own remote:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: false,
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store('agent');
await record.store('endpoints');
```

**Failure Scenarios**

**i. `Write to Bob's endpoint(s) all fail`**
```typescript
// retry Bob's endpoint(s) first
await record.send(bobDid);
// if write to Bob's endpoint(s) succeed this time, then retry your local/agent
await record.store('agent');
// if write to Bob's endpoints and your local/agent succeed this time, retry your remote/endpoint(s)
await record.store('endpoints');
```

**ii. `Write to Bob's endpoint(s) succeeds but your local/agent fails`**
```typescript
// retry your local/agent
await record.store('agent');
// if write to your your local/agent succeeds this time, retry your remote/endpoint(s)
await record.store('endpoints');
```

**iii. `Write to Bob's endpoint(s) and your local/agent succeed, but remote/endpoint(s) fail`**
```typescript
// retry your remote/endpoint(s)
await record.store('endpoints');
```

---

15. Someone else's remote + your own remote + your own local:
```typescript=
const { record } = await web5.dwn.records.write({
  to: bobDid,
  store: false,
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store('endpoints');
await record.store('agent');
```


**Failure Scenarios**

**i. `Write to Bob's endpoint(s) all fail`**
```typescript
// retry Bob's endpoint(s) first
await record.send(bobDid);
// if write to Bob's endpoint(s) succeed this time, then retry your remote/endpoint(s)
await record.store('endpoints');
// if write to Bob's endpoints and your remote/endpoint(s) succeed this time, retry your local/agent
await record.store('agent');
```

**ii. `Write to Bob's endpoint(s) succeeds but your remote/agent fails`**
```typescript
// retry your remote/endpoint(s)
await record.store('endpoints');
// if write to your remote/endpoint(s) succeed this time, retry your local/agent
await record.store('agent');
```

**iii. `Write to Bob's endpoint(s) and your remote/endpoint(s) succeed, but local/agent fails`**
```typescript
// retry your local/agent
await record.store('agent');
```