---
# System prepended metadata

title: '`web5.dwn.records` proposal'

---

# `web5.dwn.records` proposal

```javascript=
const { web5, myDid } = await Web5.connect();

// write to your agent's dwn (aka write to the dwn of the agent you're _connected_ to)
const { record, status } = await web5.dwn.records.write({
  data: {
    amount: 50,
    sourceCurrency: 'USD',
    targetCurrency: 'BTC'
  },
  message: {
    protocol: 'tbdex',
    schema: 'http://tbdex.io/rfq'
  }
});

// push this record immediately to your did-relative dwns (a.k.a cloud dwns)
await record.push();

// send that record to pfi's did
await record.send(pfiDid);

// query PFI's dwn for reply to RFQ
const { records } = await web5.dwn.records.send({
  method: 'query',
  target: pfiDid,
  message: {
    filter: {
      protocol: 'tbdex',
      contextId: record.contextId
    }
  }
});
```


### `web5.dwn.records.*` usage:

**`send(bobDid)`, `store()`, and `push()` instance methods added to `Record`**
- 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()` will have the effect of writing the message/data to your agent's dwn.  

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

2. Your own remote:
```typescript=
await web5.dwn.records.send({
  target: aliceDid,
  method: 'write',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});
```

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

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

await record.sync() // sugar for dwn.records.send;
```

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

await record.send(bobDid); // sugar for dwn.records.send
```

6. Your own remote + your own local:
```typescript=
const { record } = await web5.dwn.records.send({
  target: aliceDid,
  method: 'write',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.store(); // sugar for not calling records.write again
```

7. Your own remote + someone else's remote:
```typescript=
const { record } = await web5.dwn.records.send({
  target: aliceDid,
  method: 'write',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.send(bobDid);
```

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

await record.store();
```

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

await record.send(aliceDid);
```

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

await record.push();
await record.send(bobDid);
```

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

await record.send(bobDid);
await record.push();
```

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

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

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

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

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


await record.store();
await record.push();
```

15. Someone else's remote + your own remote + your own local:
```typescript=

const sendOpts = {

}
const { record } = await web5.dwn.records.send({
  target: bobDid,
  method: 'write',
  data: 'hi',
  message: {
    "schema": 'whatever'
  }
});

await record.send(aliceDid)
await record.store();
```

Given this, the supporting all other methods fits in the same:
* query, delete, read from someone else? use `.send`
* your own? uses `records.*`
* methods hanging off `record`