Skip to content

Commit f74a00a

Browse files
authored
Initial commit (#8)
1 parent f88fe2b commit f74a00a

24 files changed

+29344
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "Example Pyth App"
3+
version = "0.0.1"
4+
upgrade_policy = "compatible"
5+
6+
[dependencies]
7+
Pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "target_chains/aptos/contracts", rev = "main" }
8+
9+
[addresses]
10+
example = "0xac74082dfffb80824955aaefb2b0a98634b1368e37f42cbff14564ea430b97dc"
11+
# On deployment, these should be overridden with --named-addresses using the addresses
12+
# documented at https://docs.pyth.network/documentation/pythnet-price-feeds/aptos#addresses
13+
pyth = "_"
14+
deployer = "_"
15+
wormhole = "_"
16+
17+
[dev-addresses]
18+
pyth = "0xe2f37b8ac45d29d5ea23eb7d16dd3f7a7ab6426f5a998d6c23ecd3ae8d9d29eb"
19+
deployer = "0x277fa055b6a73c42c0662d5236c65c864ccbf2d4abd21f174a30c8b786eab84b"
20+
wormhole = "0x251011524cd0f76881f16e7c2d822f0c1c9510bfd2430ba24e1b3d52796df204"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module example::example {
2+
use pyth::pyth;
3+
use pyth::price::Price;
4+
use pyth::price_identifier;
5+
use aptos_framework::coin;
6+
7+
/// Updates the Pyth price feeds using the given pyth_update_data, and then returns
8+
/// the BTC/USD price.
9+
///
10+
/// https://github.com/pyth-network/pyth-js/tree/main/pyth-aptos-js should be used to
11+
/// fetch the pyth_update_data off-chain and pass it in. More information about how this
12+
/// works can be found at https://docs.pyth.network/documentation/pythnet-price-feeds/aptos
13+
public fun get_btc_usd_price(user: &signer, pyth_update_data: vector<vector<u8>>): Price {
14+
15+
// First update the Pyth price feeds
16+
let coins = coin::withdraw(user, pyth::get_update_fee(&pyth_update_data));
17+
pyth::update_price_feeds(pyth_update_data, coins);
18+
19+
// Price Feed Identifier of BTC/USD in Testnet
20+
let btc_price_identifier = x"f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b";
21+
22+
// Now we can use the prices which we have just updated
23+
let btc_usd_price_id = price_identifier::from_byte_vec(btc_price_identifier);
24+
pyth::get_price(btc_usd_price_id)
25+
26+
}
27+
}

price_feeds/aptos/mint_nft/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.aptos
2+
build

price_feeds/aptos/mint_nft/Move.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "Examples"
3+
version = "0.0.0"
4+
upgrade_policy = "compatible"
5+
6+
[dependencies]
7+
AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-framework/", rev = "main" }
8+
AptosToken = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-token/", rev = "main" }
9+
Pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "target_chains/aptos/contracts", rev = "main" }
10+
11+
[addresses]
12+
# These are testnet addresses https://docs.pyth.network/documentation/pythnet-price-feeds/aptos#addresses
13+
aptos_framework = "0x1"
14+
mint_nft = "0x19f8503273cdb5aa93ffe4539277684615242127aa2e65ef91424136a316c9c7"
15+
pyth = "0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387"
16+
deployer = "0xb31e712b26fd295357355f6845e77c888298636609e93bc9b05f0f604049f434"
17+
wormhole = "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625"
18+
19+
[dev-addresses]
20+
mint_nft = "0xb138581594ebd7763cfa3c3e455050139b7304c6d41e7094a1c78da4e6761ed8"
21+
pyth = "0xe2f37b8ac45d29d5ea23eb7d16dd3f7a7ab6426f5a998d6c23ecd3ae8d9d29eb"
22+
deployer = "0x277fa055b6a73c42c0662d5236c65c864ccbf2d4abd21f174a30c8b786eab84b"
23+
wormhole = "0x251011524cd0f76881f16e7c2d822f0c1c9510bfd2430ba24e1b3d52796df204"

price_feeds/aptos/mint_nft/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Example Full-Stack App: 1$ Mint
2+
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$.
6+
This example is intended to be run on Aptos testnet because it depends on Pyth and Wormhole existing onchain.
7+
8+
### Important files :
9+
10+
- `./sources/minting.move` has the smart contract logic (the code that will run onchain)
11+
- `./app/src/App.tsx` has the React application. The core logic of how the frontend will interact with the wallet and the blockchain.
12+
Both combined contain the key pieces of code needed to make an Aptos fullstack app using Pyth!
13+
14+
### How to deploy the smart contract :
15+
16+
- Use `aptos init` with rest_url : `https://testnet.aptoslabs.com/` and faucet `https://faucet.testnet.aptoslabs.com` to generate a new keypair.
17+
- 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.
18+
- Get your account address from `.aptos/config.yaml` and replace `mint_nft="0x19f8503273cdb5aa93ffe4539277684615242127aa2e65ef91424136a316c9c7"` by `mint_nft="<ADDRESS>"` in `Move.toml`
19+
- `aptos move compile`
20+
- `aptos move publish`
21+
22+
### How to run the webapp :
23+
24+
- In `app/src/App.tsx` replace `const MINT_NFT_MODULE = "0x19f8503273cdb5aa93ffe4539277684615242127aa2e65ef91424136a316c9c7"` by `const MINT_NFT_MODULE = "<ADDRESS>"` the address of your module from above.
25+
- `npm install`
26+
- `npm run start`
27+
- Go to `http://localhost:3000/` in your browser and use Petra wallet to transact with the app.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

0 commit comments

Comments
 (0)