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

Sentry image

Make it make sense

Only get the information you need to fix your code that’s broken with Sentry.

Start debugging →

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay