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

Runner H image

Forgot Again? Let Runner H Fix It For You

From booking the restaurant to sending the invite and apology message — Runner H makes it up for you. Yes, even your mess-ups are now automated.

Try Runner H

Top comments (0)

Dev Diairies image

User Feedback & The Pivot That Saved The Project

🔥 Check out Episode 3 of Dev Diairies, following a successful Hackathon project turned startup.

Watch full video 🎥

👋 Kindness is contagious

Embark on this engaging article, highly regarded by the DEV Community. Whether you're a newcomer or a seasoned pro, your contributions help us grow together.

A heartfelt "thank you" can make someone’s day—drop your kudos below!

On DEV, sharing insights ignites innovation and strengthens our bonds. If this post resonated with you, a quick note of appreciation goes a long way.

Get Started