[][src]Function hdk::commit_entry

pub fn commit_entry(
    entry_type_name: &str,
    entry_value: Value
) -> ZomeApiResult<HashString>

Attempts to commit an entry to your local source chain. The entry will have to pass the defined validation rules for that entry type. If the entry type is defined as public, will also publish the entry to the DHT. Returns either an address of the committed entry as a string, or an error.

Examples

pub fn handle_create_post(content: String) -> serde_json::Value {
    let maybe_address = hdk::commit_entry("post", json!({
        "content": content,
        "date_created": "now"
    }));
    match maybe_address {
        Ok(post_address) => json!({"address": post_address}),
        Err(hdk_error) => hdk_error.to_json(),
    }
}