-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instructions + example client for devnet
- Loading branch information
Showing
4 changed files
with
119 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# chainlink-solana | ||
|
||
## Running the example on devnet | ||
|
||
Generate a new wallet: | ||
|
||
``` | ||
solana-keygen new -o id.json | ||
solana-keygen pubkey id.json | ||
``` | ||
|
||
Airdrop some tokens: | ||
|
||
``` | ||
solana airdrop 4 <RECIPIENT_ACCOUNT_ADDRESS> --url https://api.devnet.solana.com | ||
``` | ||
|
||
Build and deploy the contract: | ||
|
||
``` | ||
anchor build | ||
anchor deploy --provider.cluster devnet | ||
``` | ||
|
||
Extract the `program_id` and insert it into `client.js` | ||
|
||
``` | ||
solana-keygen pubkey target/deploy/hello_world-keypair.json | ||
``` | ||
|
||
Now run the Node.JS client: | ||
|
||
``` | ||
ANCHOR_PROVIDER_URL=https://api.devnet.solana.com ANCHOR_WALLET=id.json node client.js | ||
Running client... | ||
Fetching transaction logs... | ||
[ | ||
'Program <PROGRAM_ID> invoke [1]', | ||
'Program log: Instruction: Execute', | ||
'Program DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g invoke [2]', | ||
'Program log: Instruction: Query', | ||
'Program DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g consumed 2916 of 196135 compute units', | ||
'Program return: DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g 6NQDALZQ7mEAAAAAQH32BQAAAAAAAAAAAAAAAA==', | ||
'Program DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g success', | ||
'Program DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g invoke [2]', | ||
'Program log: Instruction: Query', | ||
'Program DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g consumed 2943 of 189793 compute units', | ||
'Program return: DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g CgAAAFVTRFQgLyBVU0Q=', | ||
'Program DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g success', | ||
'Program DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g invoke [2]', | ||
'Program log: Instruction: Query', | ||
'Program DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g consumed 2332 of 183111 compute units', | ||
'Program return: DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g CA==', | ||
'Program DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g success', | ||
'Program log: USDT / USD price is 1.00040000', | ||
'Program ENzTWES9dJhCDh2cBdxysQyzBUTxUqokPcojSj5phykw consumed 21585 of 200000 compute units', | ||
'Program return: DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g CA==', | ||
'Program ENzTWES9dJhCDh2cBdxysQyzBUTxUqokPcojSj5phykw success' | ||
] | ||
Success | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const anchor = require("@project-serum/anchor"); | ||
|
||
// devnet IDs | ||
const CHAINLINK_PROGRAM_ID = "DWqYEinRbZWtuq1DiDYvmexAKFoyjSyazZZUvdgPHT5g"; | ||
// USDT/USD | ||
const CHAINLINK_FEED = "CwBg8pxL73LvuJ781cWBGF1e64G2z7AbZ22J2g8Lp35a"; | ||
|
||
const provider = anchor.Provider.env(); | ||
|
||
// Configure the cluster. | ||
anchor.setProvider(provider); | ||
|
||
async function main() { | ||
// #region main | ||
// Read the generated IDL. | ||
const idl = JSON.parse( | ||
require("fs").readFileSync("./target/idl/hello_world.json", "utf8") | ||
); | ||
|
||
// Address of the deployed program. | ||
const programId = new anchor.web3.PublicKey("<YOUR-PROGRAM-ID>"); | ||
|
||
// Generate the program client from IDL. | ||
const program = new anchor.Program(idl, programId); | ||
|
||
// Execute the RPC. | ||
let tx = await program.rpc.execute({ | ||
accounts: { | ||
chainlinkFeed: CHAINLINK_FEED, | ||
chainlinkProgram: CHAINLINK_PROGRAM_ID | ||
}, | ||
options: { commitment: "confirmed" }, | ||
}); | ||
|
||
console.log("Fetching transaction logs..."); | ||
let t = await provider.connection.getConfirmedTransaction(tx, "confirmed"); | ||
console.log(t.meta.logMessages); | ||
// #endregion main | ||
} | ||
|
||
console.log("Running client..."); | ||
main().then(() => console.log("Success")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters