admin管理员组

文章数量:1128991

I am new to using the Cairo programming language, and I am also trying to make use of the Pragma docs to build a price feed: /v1/Resources/Consuming%20Data%20Feed I am following the guide as it is however, when copying their code into my own project it is littered with errors, the code is as follows:

use starknet::ContractAddress;

#[starknet::interface]
trait HackTemplateABI<TContractState> {
    fn get_asset_price(self: @TContractState, asset_id: felt252) -> u128;
}



#[starknet::contract]
mod HackTemplate {
    use super::{ContractAddress, HackTemplateABI};
    use starknet::array::{ArrayTrait, SpanTrait};
    use starknet::traits::{Into, TryInto};
    use pragma_lib::abi::{
            IPragmaABIDispatcher, IPragmaABIDispatcherTrait};
    use pragma_lib::types::{DataType, PragmaPricesResponse};
    use starknet::alexandria_math::math::fpow;
    use starknet::option::OptionTrait;
    const ETH_USD: felt252 = 19514442401534788;  //ETH/USD to felt252, can be used as asset_id
    const BTC_USD: felt252 = 18669995996566340;  //BTC/USD


    #[storage]
    struct Storage {
        pragma_contract: ContractAddress,
        summary_stats: ContractAddress,
    }

    #[constructor]
    fn constructor(ref self: ContractState, pragma_address: ContractAddress, summary_stats_address : ContractAddress)
    {
        self.pragma_contract.write(pragma_address);
        self.summary_stats.write(summary_stats_address);
    }
    #[abi(embed_v0)]
    impl HackTemplateABIImpl of HackTemplateABI<ContractState> {


        fn get_asset_price(self: @ContractState, asset_id: felt252) -> u128 {
            // Retrieve the oracle dispatcher
            let oracle_dispatcher = IPragmaABIDispatcher {
                contract_address: self.pragma_contract.read()
            };

            // Call the Oracle contract, for a spot entry
            let output: PragmaPricesResponse = oracle_dispatcher
                .get_data_median(DataType::SpotEntry(asset_id));

            return output.price;
        }

    }
}

The problem areas are:

  • use starknet::array::{ArrayTrait, SpanTrait}; array - "Identifier not found."
  • use starknet::traits::{Into, TryInto}; traits - "Identifier not found."
  • use starknet::alexandria_math::math::fpow; alexandria_math - "Identifier not found."
  • use starknet::option::OptionTrait; option - "Indetifier not found"
  • self.pragma_contract.write(pragma_address); write - "Method write not found on type core::starknet::storage::storage_base::StorageBase::<core::starknet::storage::Mutable::<core::starknet::contract_address::ContractAddress>>"
  • contract_address: self.pragma_contract.read() read- "Method read not found on type core::starknet::storage::storage_base::StorageBase::<core::starknet::storage::Mutable::<core::starknet::contract_address::ContractAddress>>"

I have found some links online speaking about Cairo having an issue since updating from v2.5.0 when it should have been v3.0.0?

On the cairo book website this is what i found out about the identifier issue but i am struggling to find a fix: Identifier not found.: this error message is a bit aspecific but might indicate that:

"Identifier not found.: this error message is a bit aspecific but might indicate that: A variable is being used before it has been declared. Make sure to declare variables with the let keyword. The path to bring an item into scope is wrongly defined. Make sure to use valid paths."

Any help would be greatly appreciated

.html

本文标签: starknetScarb Pragma Identifier Not FoundStack Overflow