🔵How to Integration APassOracle

Contract

Access off-chain

You can easily access AOracle real-time data through API.

Visit AOracle Board at http://aptpp.com/#/aoracle , choose your pair and you will get API Url like:

The maximum delay between on-chain data and API data is 5 seconds

Access on-chain

You should add a dependency in your project move.toml

[package]
name = "YourProject"
version = "0.0.1"
upgrade_policy = "compatible"

[dependencies]
AptosFramework = { local = "../../aptos-core-main/aptos-move/framework/aptos-framework" }
AptosStdlib = { local = "../../aptos-core-main/aptos-move/framework/aptos-stdlib" }
AptosToken = { local = "../../aptos-core-main/aptos-move/framework/aptos-token" }

// Add this line
AOracle = { git = "https://github.com/AptosPassport/aoracle-contract.git", rev = "main" }

Then add the module reference in the move code, and use AOracle like follow:

module YourProject::SomeModule {
  use std::error;
  use std::vector;
  use std::signer;
	
  // Use AOracle moudule
  use AOracle::oracle;
	
  /**
  * @notice Get latest recorded price from oracle
  */
  fun getPriceFromOracle(): (u64, u64) {	
    let (roundId, price, _, timestamp, _) = 
        oracle::latestRoundDataByName(string::utf8("APTUSDT"));
    (roundId, price)
  }
}

Last updated