1

i want to add pallet-contracts into substrate on branch but i faced errro .

Repository

i will tell you step by step what i did :

Step One : Add Depency Pallets

pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git",  " branch" = "polkadot-v0.9.35" }
pallet-contracts-primitives = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git",  " branch" = "polkadot-v0.9.35" }
pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.27" }

Step Two : Add Pallets Config

   parameter_types! {
    pub TombstoneDeposit: Balance = deposit(
        1,
        <pallet_contracts::Pallet<Runtime>>::contract_info_size()
    );
    pub DepositPerContract: Balance = TombstoneDeposit::get();
    pub const DepositPerStorageByte: Balance = deposit(0, 1);
    pub const DepositPerStorageItem: Balance = deposit(1, 0);
    pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * DAYS);
    pub const SurchargeReward: Balance = 150 * MILLICENTS;
    pub const SignedClaimHandicap: u32 = 2;
    pub const MaxValueSize: u32 = 16 * 1024;
    // The lazy deletion runs inside on_initialize.
    pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *
     BlockWeights::get().max_block;
    // The weight needed for decoding the queue should be less or equal than a fifth
    // of the overall weight dedicated to the lazy deletion.
    pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / (
        <Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -
        <Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)
     )) / 5) as u32;

    pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
}

impl pallet_contracts::Config for Runtime {
    type Time = Timestamp;
    type Randomness = RandomnessCollectiveFlip;
    type Currency = Balances;
    type Event = Event;
    type RentPayment = ();
    type SignedClaimHandicap = SignedClaimHandicap;
    type TombstoneDeposit = TombstoneDeposit;
    type DepositPerContract = DepositPerContract;
    type DepositPerStorageByte = DepositPerStorageByte;
    type DepositPerStorageItem = DepositPerStorageItem;
    type RentFraction = RentFraction;
    type SurchargeReward = SurchargeReward;
    type WeightPrice = pallet_transaction_payment::Module<Self>;
    type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
    type ChainExtension = ();
    type DeletionQueueDepth = DeletionQueueDepth;
    type DeletionWeightLimit = DeletionWeightLimit;
    type Call = Call;
    /// The safest default is to allow no calls at all.
    ///
    /// Runtimes should whitelist dispatchables that are allowed to be called from contracts
    /// and make sure they are stable. Dispatchables exposed to contracts are not allowed to
    /// change because that would break already deployed contracts. The `Call` structure itself
    /// is not allowed to change the indices of existing pallets, too.
    type CallFilter = Nothing;
    type Schedule = Schedule;
    type CallStack = [pallet_contracts::Frame<Self>; 31];
}

Step two : Add runtime api

   impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>
    for Runtime
{
    fn call(
        origin: AccountId,
        dest: AccountId,
        value: Balance,
        gas_limit: u64,
        input_data: Vec<u8>,
    ) -> ContractExecResult {
        let (exec_result, gas_consumed) =
            Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);
        match exec_result {
            Ok(v) => ContractExecResult::Success {
                flags: v.flags.bits(),
                data: v.data,
                gas_consumed: gas_consumed,
            },
            Err(_) => ContractExecResult::Error,
        }
    }

    fn get_storage(
        address: AccountId,
        key: [u8; 32],
    ) -> pallet_contracts_primitives::GetStorageResult {
        Contracts::get_storage(address, key)
    }

    fn rent_projection(
        address: AccountId,
    ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {
        Contracts::rent_projection(address)
    }
}

but it show me this error :

no matching package named `pallet-contracts-rpc-runtime-api` found location searched: https://github.com/paritytech/substrate.git

whats the problem ? how can i solve this problem ?

1 Answer 1

1

Delete the pallet-contracts-rpc-runtime-api from the runtime, it doesn't have to be there anymore.

See this previous answer from StackExchange for more information:

The reason is that everything under runtime/ will be run in an isolated no_std sandbox mode in WebAssembly, whereas the RPC endpoints are very much exposed to the outside networking world.

I recommend you to check the code of a parachain that runs in rococo and has the pallet-contract in it, if you want to use it as a guide about how to add the pallet.

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.