Skip to main content

.put()

The .put() method writes data to the graph. It handles conflict resolution using GUN’s CRDT algorithm and automatically syncs changes to connected peers.

Signature

Parameters

object | string | number | boolean | null | function
The data to write. Can be:
  • Object: Creates or updates a node with properties
  • Primitive: Stores a scalar value (string, number, boolean, null)
  • Function: Deferred write - function receives callback to pass data
  • Link: Another GUN reference (creates a relationship)
Note: Arrays are not directly supported. Use .set() for collections.
function
Called after the write is acknowledged. Receives an acknowledgment object.Signature: function(ack)
  • ack.err - Error object if write failed
  • ack.ok - Success confirmation
  • ack['@'] - Acknowledgment ID
object
Advanced options for write behavior

Return Value

Returns the same GUN chain reference for method chaining.

Examples

Write Object Data

Update Individual Properties

Write with Callback

Deferred Write with Function

Delete Properties

Create Relationships

Implementation Details

From the source code (put.js:4-78):
The .put() method:
  1. Validates the data structure
  2. Walks the graph to find nested objects
  3. Assigns state timestamps for conflict resolution
  4. Handles circular references
  5. Emits updates to connected peers
  6. “Stuns” reads during writes to prevent race conditions

Conflict Resolution

GUN uses state-based CRDTs for automatic conflict resolution:

Valid Data Types

From valid.js, GUN supports:
  • null (for deletes)
  • string
  • number (except ±Infinity)
  • boolean
  • Objects (nested graphs)
  • Soul references: { '#': 'node-id' }

Invalid Data

Notes

  • Writes are asynchronous and eventually consistent
  • Data is automatically synchronized to all connected peers
  • Partial updates merge with existing data (they don’t replace it)
  • Circular references are automatically detected and handled
  • State timestamps are automatically generated using Gun.state()