Skip to content

Commit a19cd93

Browse files
authored
Update example to use APT pricefeed (#365)
* Update example * Update address of example contract
1 parent a9a1fb7 commit a19cd93

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

aptos/examples/mint_nft/Move.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "
1111
[addresses]
1212
# These are testnet addresses https://docs.pyth.network/consume-data/aptos#addresses
1313
aptos_framework = "0x1"
14-
mint_nft = "_"
14+
mint_nft = "0x19f8503273cdb5aa93ffe4539277684615242127aa2e65ef91424136a316c9c7"
1515
pyth = "0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387"
1616
deployer = "0xb31e712b26fd295357355f6845e77c888298636609e93bc9b05f0f604049f434"
1717
wormhole = "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625"

aptos/examples/mint_nft/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Example Full-Stack App: 100$ USD Mint
1+
# Example Full-Stack App: 1$ Mint
22

3-
The goal of this contract is managing an NFT mint where the mint is paid in native currency but the cost of one NFT is always 100$.
3+
The example contract is deployed at : `0x19f8503273cdb5aa93ffe4539277684615242127aa2e65ef91424136a316c9c7`
4+
5+
The goal of this contract is managing an NFT mint where the mint is paid in native currency but the cost of one NFT is always 1$.
46
This example is intended to be run on Aptos testnet because it depends on Pyth and Wormhole existing onchain.
57

68
### Important files :
@@ -12,13 +14,13 @@ Both combined contain the key pieces of code needed to make an Aptos fullstack a
1214

1315
- Use `aptos init` with rest_url : `https://testnet.aptoslabs.com/` and faucet `https://faucet.testnet.aptoslabs.com` to generate a new keypair.
1416
- Use a faucet to airdrop testnet APT to your newly created account by calling `aptos account fund-with-faucet --account default`. If this doesn't work, I have had success importing my private key from `.aptos/config.yaml` into Petra and clicking the airdrop button. Otherwise send APT from another account.
15-
- Get your account address from `.aptos/config.yaml` and replace `mint_nft="_"` by `mint_nft="<ADDRESS>"` in `Move.toml`
17+
- Get your account address from `.aptos/config.yaml` and replace `mint_nft="0x19f8503273cdb5aa93ffe4539277684615242127aa2e65ef91424136a316c9c7"` by `mint_nft="<ADDRESS>"` in `Move.toml`
1618
- `aptos move compile`
1719
- `aptos move publish`
1820

1921
### How to run the webapp :
2022

21-
- In `app/src/App.tsx` replace `const MINT_NFT_MODULE = "_"` by `const MINT_NFT_MODULE = "<ADDRESS>"` the address of your module from above.
23+
- In `app/src/App.tsx` replace `const MINT_NFT_MODULE = "0x19f8503273cdb5aa93ffe4539277684615242127aa2e65ef91424136a316c9c7"` by `const MINT_NFT_MODULE = "<ADDRESS>"` the address of your module from above.
2224
- `npm install`
2325
- `npm run start`
2426
- Go to `http://localhost:3000/` in your browser and use Petra wallet to transact with the app.

aptos/examples/mint_nft/app/src/App.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from "react";
22
import logo from "./logo.svg";
33
import "./App.css";
44
import { Price, PriceFeed } from "@pythnetwork/pyth-common-js";
5-
import { AptosClient } from "aptos";
65
import { AptosPriceServiceConnection } from "@pythnetwork/pyth-aptos-js";
76

87
// Please read https://docs.pyth.network/consume-data before building on Pyth
@@ -16,11 +15,11 @@ const testnetConnection = new AptosPriceServiceConnection(
1615
); // Price service client used to retrieve the offchain VAAs to update the onchain price
1716

1817
// Price id : this is not an aptos account but instead an opaque identifier for each price https://pyth.network/developers/price-feed-ids/#pyth-cross-chain-testnet
19-
const ETH_USD_TESTNET_PRICE_ID =
20-
"0xca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6";
18+
const APT_USD_TESTNET_PRICE_ID =
19+
"0x44a93dddd8effa54ea51076c4e851b6cbbfd938e82eb90197de38fe8876bb66e";
2120

2221
// Aptos modules : These are testnet addresses https://docs.pyth.network/consume-data/aptos#addresses
23-
const MINT_NFT_MODULE = "_";
22+
const MINT_NFT_MODULE = "0x19f8503273cdb5aa93ffe4539277684615242127aa2e65ef91424136a316c9c7";
2423

2524
/// React component that shows the offchain price and confidence interval
2625
function PriceText(props: { price: Price | undefined }) {
@@ -31,7 +30,7 @@ function PriceText(props: { price: Price | undefined }) {
3130
{" "}
3231
<p>
3332
{" "}
34-
Current ETH/USD price:{" "}
33+
Current APT/USD price:{" "}
3534
<span style={{ color: "green" }}>
3635
{" "}
3736
{price.getPriceAsNumberUnchecked().toFixed(3) +
@@ -44,7 +43,7 @@ function PriceText(props: { price: Price | undefined }) {
4443
Current NFT price:{" "}
4544
<span style={{ color: "green" }}>
4645
{" "}
47-
{(100 / price.getPriceAsNumberUnchecked()).toFixed(5)} APT{" "}
46+
{(1 / price.getPriceAsNumberUnchecked()).toFixed(5)} APT{" "}
4847
</span>{" "}
4948
</p>{" "}
5049
</div>
@@ -68,7 +67,7 @@ function App() {
6867

6968
// Subscribe to offchain prices. These are the prices that a typical frontend will want to show.
7069
testnetConnection.subscribePriceFeedUpdates(
71-
[ETH_USD_TESTNET_PRICE_ID],
70+
[APT_USD_TESTNET_PRICE_ID],
7271
(priceFeed: PriceFeed) => {
7372
const price = priceFeed.getPriceUnchecked(); // Fine to use unchecked (not checking for staleness) because this must be a recent price given that it comes from a websocket subscription.
7473
setPythOffChainPrice(price);
@@ -120,7 +119,7 @@ function App() {
120119

121120
async function sendMintTransaction() {
122121
const priceFeedUpdateData = await testnetConnection.getPriceFeedsUpdateData([
123-
ETH_USD_TESTNET_PRICE_ID,
122+
APT_USD_TESTNET_PRICE_ID,
124123
]);
125124
const mintTransaction = {
126125
type: "entry_function_payload",

aptos/examples/mint_nft/sources/minting.move

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ module mint_nft::minting {
1616
use aptos_std::math64::pow;
1717
use aptos_token::token::{Self, TokenDataId};
1818

19-
// WARNING This is actually the ETH/USD while APT is not listed
2019
// For the entire list of price_ids head to https://pyth.network/developers/price-feed-ids/#pyth-cross-chain-testnet
21-
// TODO : Update to the real APT/USD when it's out
22-
const APTOS_USD_PRICE_FEED_IDENTIFIER : vector<u8> = x"ca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6";
20+
const APTOS_USD_PRICE_FEED_IDENTIFIER : vector<u8> = x"44a93dddd8effa54ea51076c4e851b6cbbfd938e82eb90197de38fe8876bb66e";
2321

2422
// This event stores the receiver of the NFT and the TokenDataId of the NFT
2523
struct TokenMintingEvent has drop, store {
@@ -81,7 +79,7 @@ module mint_nft::minting {
8179
});
8280
}
8381

84-
/// Mint an edition of the Pythian NFT pay 100 USD in native APT
82+
/// Mint an edition of the Pythian NFT pay 1 USD in native APT
8583
public entry fun mint_nft(receiver : &signer, vaas : vector<vector<u8>>) acquires CollectionTokenMinter{
8684
// Fetch the signer capability to mint the NFT
8785
let collection_token_minter = borrow_global_mut<CollectionTokenMinter>(@mint_nft);
@@ -94,7 +92,7 @@ module mint_nft::minting {
9492
let price_positive = i64::get_magnitude_if_positive(&price::get_price(&price)); // This will fail if the price is negative
9593
let expo_magnitude = i64::get_magnitude_if_negative(&price::get_expo(&price)); // This will fail if the exponent is positive
9694

97-
let price_in_aptos_coin = (100 * OCTAS_PER_APTOS * pow(10, expo_magnitude)) / price_positive; // 100 USD in AptosCoin
95+
let price_in_aptos_coin = (OCTAS_PER_APTOS * pow(10, expo_magnitude)) / price_positive; // 1 USD in APT
9896

9997
coin::transfer<aptos_coin::AptosCoin>(receiver, @mint_nft, price_in_aptos_coin); // Pay for the NFT
10098
}

0 commit comments

Comments
 (0)