Amiya Behera
Amiya Behera

Reputation: 2270

into_sub_account method not found

I am trying to use PALLET_ID

const PALLET_ID: PalletId = PalletId(*b"ex/cfund");
 fn fund_account_id(index: FundIndex) -> T::AccountId {
            PALLET_ID.into_sub_account(index)
        }

But its giving error:

 method not found in `frame_support::PalletId`

Docs: Link
All of the methods are inaccessible and giving error.

Version:
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-10'
version = '4.0.0-dev'

Upvotes: 0

Views: 168

Answers (1)

gui
gui

Reputation: 516

This method is part of the trait AccountIdConversion which is implemented for the type PalletId. So you need to have the trait in scope or call the method from the trait explicitly.

So like:

use sp_runtime::traits::AccountIdConversion;
const PALLET_ID: frame_support::PalletId = frame_support::PalletId(*b"ex/cfund");
fn fund_account_id(index: u32) -> u128 {
    PALLET_ID.into_sub_account(index)
}

or

const PALLET_ID: frame_support::PalletId = frame_support::PalletId(*b"ex/cfund");
fn fund_account_id(index: u32) -> u128 {
    sp_runtime::traits::AccountIdConversion::into_sub_account(&PALLET_ID, index)
}

Also in your example the type FundIndex needs to implement Encode to satisfy the trait implementation.

Upvotes: 1

Related Questions