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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started