DEV Community

Marc P
Marc P

Posted on

How can I deserialize vectors in SUI from move contract?

I have problems in deserializing vectors from move contract in SUI.

This is backend codes.

module forum::forum {

use std::option::{ Option, some};
use std::string::{Self, String};
use std::vector::{ empty, push_back, contains};  
use sui::object::{Self, UID};
use sui::transfer;
use sui::tx_context::{Self, TxContext};
use sui::url::{Self, Url};
use sui::clock::{Self, Clock};

struct Forum has key {
    id: UID,        
    posts : vector<Post>,
}

struct Post has key, store {
    id: UID,
    title: String,
    content: String,
    creator: address,
    vote: u64, 
    comments: vector<Comment>      
}

struct Comment has key, store {
    id: UID,
    created_at: u64,
    content: String,
    reply: vector<Reply>
}


struct Reply has key, store {
    id : UID,
    created_at: u64,
    content : String,
}
    push_back(community_ref,  _community);

    if(!contains(&gilder.members, &creator)) {
        push_back(&mut gilder.members, creator)
    }
}

public fun get_posts(forum: &Forum) : &vector<Post> {
    return &forum.posts
}
Enter fullscreen mode Exit fullscreen mode

}

I have to deserialize this codes in frontend(for SUI).

I know I have to use bcs to deserialize post vectors from backend but I didn't find the solution.

Please help me if you know the solution.

Thanks

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE