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 - "Methodwrite
not found on typecore::starknet::storage::storage_base::StorageBase::<core::starknet::storage::Mutable::<core::starknet::contract_address::ContractAddress>>
"contract_address: self.pragma_contract.read()
read- "Methodread
not found on typecore::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
版权声明:本文标题:starknet - Scarb Pragma Identifier Not Found - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736730038a1949940.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论