# CosmosGrainStorage.WriteStateAsync(string, GrainId, IGrainState&lt;T&gt;, CancellationToken)

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.persistence.cosmos/orleans.persistence.cosmos.cosmosgrainstorage/) | [Methods](/orleans/docs/api/csharp/microsoft.orleans.persistence.cosmos/orleans.persistence.cosmos.cosmosgrainstorage/methods/)

[Source](https://github.com/dotnet/orleans/blob/fbe240c34e9a1389ca5ab2d52f292ed8749ea530/src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs#L126)

```csharp
public Task WriteStateAsync<T>(string grainType, GrainId grainId, IGrainState<T> grainState, CancellationToken cancellationToken)
```

Write data function for this storage instance.

### Parameters

- `grainType` (`string`): Name of the state for this grain.
- `grainId` (`GrainId`): Grain ID.
- `grainState` (`IGrainState<T>`): State data object to be written for this grain.
- `cancellationToken` (`CancellationToken`): The cancellation token.

### Returns

Completion promise for the Write operation on the specified grain.
