Skip to content

An example contract for Solana and the Anchor library #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/sol-anchor-contract/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
yarn.lock
Cargo.lock
.anchor
.DS_Store
target
**/*.rs.bk
node_modules
test-ledger
10 changes: 10 additions & 0 deletions examples/sol-anchor-contract/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[programs.devnet]
example_sol_anchor_contract = "Fwn1fCmbjd8d95hxY9NUUr5Xa7D13khveMnmCUFdd3ah"

[provider]
cluster = "devnet"
wallet = "~/.config/solana/id.json"

[scripts]
install = "npm install"
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 scripts/test.ts"
13 changes: 13 additions & 0 deletions examples/sol-anchor-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[workspace]
members = [
"programs/*"
]

[profile.release]
overflow-checks = true
lto = "fat"
codegen-units = 1
[profile.release.build-override]
opt-level = 3
incremental = false
codegen-units = 1
30 changes: 30 additions & 0 deletions examples/sol-anchor-contract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Pyth SDK Example Program for Solana and the Anchor Library

This example implements the same functionalities as the `sol-contract` example.
The difference is that this example uses the `anchor` library while the `sol-contract` example uses the lower-level solana interface.
Please refer to the README of `sol-contract` for a description of the functionalities.

## Run this program
We assume that you have installed `anchor`, `npm` and `yarn`.

```shell
# Generate the program key
> solana-keygen new -o program_address.json

# Use the pubkey generated to replace the following two places
# "example_sol_anchor_contract" in Anchor.toml
# "declare_id!()" in programs/example-sol-anchor-contract/src/lib.rs

# Enter the directory and build this example
> cd examples/sol-contract-anchor
> anchor build

# Change the `wallet` field in Anchor.toml to your own wallet
# And then deploy the example contract; An error may occur if
# your wallet does not have enough funds
> anchor deploy --program-keypair program_address.json --program-name example-sol-anchor-contract

# Install the client dependencies and invoke this program
> anchor run install
> anchor run invoke
```
Loading