1

I have implemented ink contract which use to create token, as shown below, I have two struct with declare #[ink(storage)], I am getting below error, How to solve it.

#![cfg_attr(not(feature = "std"), no_std)]

#[ink::contract]
mod my_token {
    use super::*;

    #[ink(storage)]
    pub struct MyToken {
    
    }
    impl MyToken {
        // here are some implementation
    }
 

  
    #[ink(storage)]
    pub struct TokenValue {
        Value: u128,
    }
    
    impl Default for TokenValue {
        fn default() -> Self {
            TokenValue { value: 0 }
        }
    }
    impl TokenValue {
     // here are some implementation
    }
}

ERROR:

error: encountered multiple ink! storage structs, expected exactly one
    |
4   | / mod my_token {
5   | |     use super::*;
6   | |
7   | |     #[ink(storage)]
...   |
304 | |     }
305 | | }
    | |_^

error: ink! storage struct here
  
   |
8  | /     pub struct MyToken {
9  | |  
18 | |     }
   | |_____^

error: ink! storage struct here
    |
197 | /     pub struct TokenValue {
198 | |         Value: u128,
199 | |     }
    | |_____^

1 Answer 1

3

An ink! contract is only allowed and required to have exactly one #[ink(storage)] struct (ref)

3
  • Incase if I want use multiple struct value to be stored , How to achieve it ?
    – nagaraj
    Mar 30, 2023 at 10:14
  • I suggest going through the docs first and raise a more specific question when you have it :). In addition, check this answer as "answered" if it did. Mar 30, 2023 at 10:37
  • Inside docs look in this link
    – Ganesh11
    Mar 31, 2023 at 1:23

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.