Starter repo for all things Switchboard.
- Install node 12: https://nodejs.org/en/download/package-manager/
- Docker compose: https://docs.docker.com/compose/install/
- ts-node: https://www.npmjs.com/package/ts-node
- git
- cargo
- solana cli https://docs.solana.com/cli/install-solana-cli-tools
In this example, we will post an example Solana program that will parse and print a provided data feed.
cd $EXAMPLES_DIRECTORY
npm i
cd "$(git rev-parse --show-toplevel)/example-program"
# Build example program
cargo build-bpf --manifest-path=Cargo.toml --bpf-out-dir=$PWD
# Publish example program
export PROGRAM_PUBKEY=$(solana program deploy libswitchboard_example.so | tee /dev/tty | grep "Program Id:" | awk '{print $NF}')
#if you do not have a default signer key then you must generate one with solana-keygen before running the above command
cd ../ts-example
# Create and fund a payer account for the example
solana-keygen new --outfile example-keypair.json
solana airdrop 5 example-keypair.json --url https://api.devnet.solana.com
# Choose a feed to use in your program
# Find Data Feed Pubkeys at https://switchboard.xyz/#/explorer
export FEED_PUBKEY="<YOUR FEED PUBKEY HERE>"
# Run the example
ts-node example_1.ts --payerFile=example-keypair.json --programPubkey=${PROGRAM_PUBKEY?} --dataFeedPubkey=${FEED_PUBKEY?}
In this example, we will create our own data feed and spin up our own node to fulfill aggregator jobs.
In part a
of this example, we will:
- Create a data feed.
- Add an example job to the feed.
- Create a fulfillment manager and link it to the data feed.
- Run a Switchboard node on the new fulfillment manager.
In part b
we will:
- Call
update
on a Switchboard Feed. - Watch as the aggregator populates with results!
Part a (Run a Switchboard node on your Fulfillment Manager):
cd "$(git rev-parse --show-toplevel)/ts-example"
solana airdrop 5 example-keypair.json --url https://api.devnet.solana.com
ts-node example_2a.ts --payerFile=example-keypair.json
export FULFILLMENT_MANAGER_KEY=<FULFILLMENT MANAGER KEY HERE>
export AUTH_KEY=<AUTH KEY HERE>
docker-compose up
Part b:
FEED_PUBKEY=<FEED PUBKEY HERE>
UPDATE_AUTH_KEY=<UPDATE AUTH PUBKEY HERE>
ts-node example_2b.ts --payerFile=example-keypair.json \
--dataFeedPubkey=${FEED_PUBKEY} --updateAuthPubkey=${UPDATE_AUTH_KEY}