-
-
Save xk4r00t/e02c9fd8ab7c26a35a4cb221cbdea5ad to your computer and use it in GitHub Desktop.
Elrond serialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import from erdjs SDK | |
import { AbiRegistry, BinaryCodec } from "@elrondnetwork/erdjs"; | |
// Our base64 response buffer that was queries | |
let buffer = Buffer.from("AAAACFNvbWUgaGF0AAAAClNvbWUgc2hpcnQAACMp", "base64"); | |
// Load the main.abi.json into our program | |
let registry = await AbiRegistry.load({ files: ["main.abi.json"] }); | |
// Get MyNFT struct from the registry | |
let type = registry.getStruct("MyNFT"); | |
// Decode the base64 response using the MyNFT type | |
let result = (new BinaryCodec).decodeTopLevel(buffer, type).valueOf(); | |
// Print the result | |
console.log(result); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_std] | |
elrond_wasm::imports!(); | |
elrond_wasm::derive_imports!(); | |
#[derive(TopEncode, TopDecode, TypeAbi)] | |
pub struct MyNFT<M: ManagedTypeApi> { | |
hat: ManagedBuffer<M>, | |
shirt: ManagedBuffer<M>, | |
rarity: i32 | |
} | |
#[elrond_wasm::contract] | |
pub trait App { | |
#[init] | |
fn init(&self) {} | |
#[view(my_nft)] | |
fn my_nft(&self) -> MyNFT<Self::Api> | |
{ | |
MyNFT { | |
hat: ManagedBuffer::from(b"Some hat"), | |
shirt: ManagedBuffer::from(b"Some shirt"), | |
rarity: 9001, | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment