2

I Already write code with openbrush.io and set Attribute on constructor here my code :

#![cfg_attr(not(feature = "std"), no_std)]
#![feature(min_specialization)]
        
#[openbrush::contract]
pub mod my_psp34 {
    
    // imports from openbrush
    use openbrush::traits::String;
    use openbrush::traits::Storage;
    use openbrush::contracts::psp34::extensions::mintable::*;
    use openbrush::contracts::psp34::extensions::enumerable::*;
    use openbrush::contracts::psp34::extensions::metadata::*;

    #[ink(storage)]
    #[derive(Default, Storage)]
    pub struct Psp34Basic {
        #[storage_field]
        psp34: psp34::Data<Balances>,
        #[storage_field]
        metadata: metadata::Data,
    }
    
    // Section contains default implementation without any modifications
    impl PSP34 for Psp34Basic {}
    impl PSP34Mintable for Psp34Basic {}
    impl PSP34Enumerable for Psp34Basic {}
    impl PSP34Metadata for Psp34Basic {}
     
    impl Psp34Basic {
        #[ink(constructor)]
        pub fn new() -> Self {
            let mut _instance = Self::default();
            _instance._mint_to(_instance.env().caller(), Id::U8(1)).expect("Can mint");
            let collection_id = _instance.collection_id();
            _instance._set_attribute(collection_id.clone(), String::from("name"), String::from("PSP34BASIC"));
            _instance._set_attribute(collection_id, String::from("symbol"), String::from("PSPB"));
            _instance
        }
    }
}

The code success to deploy, when i want to get attribute using PSP34 metadata get_attribute the value is null. Please help me how i retrieve symbol attribute or name ?

here i give image how i call the attribute?

enter image description here

1 Answer 1

1

I, Already Know to Retrieve Symbol and name, create function

        //create function to get collection name and Symbol
        #[ink(message)]
        pub fn get_collection_name(&self) -> String {
            self._get_attribute(self.collection_id(), String::from("name")).unwrap()
        }
        #[ink(message)]
        pub fn get_collection_symbol(&self) -> String {
            self._get_attribute(self.collection_id(), String::from("symbol")).unwrap()
        }   

        //crate function _get_attribute
        fn _get_attribute(&self, collection_id: Id, key: String) -> Option<String> {
            self.metadata.get_attribute(collection_id, key) 
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.