Kit
Use generated Doppler SDKs with @solana/kit.
The Kit client is generated for your payload schema. It is for applications built around @solana/kit.
Generate the SDK
Doppler does not publish this client to npm. Generate it with the generate command after initializing your payload schema:
npx @blueshift-gg/doppler-cli generate ./payload.ts \
--kit-sdk ./generated/sdk/kitThe generator writes a sibling common/ package and a kit/ package. The kit package depends on common through file:../common.
Link both generated directories into your application workspace, then import from the generated package name. For a config named price-feed, the package is price-feed-kit.
Your application must provide @solana/kit, @solana-program/compute-budget, and @solana-program/system as dependencies. The generated SDK lists them as peer dependencies.
Create a Client
import { ADMIN, Doppler, PROGRAM_ID, priceFeedSerializer } from "price-feed-kit";
import {
address,
createKeyPairSignerFromBytes,
createSolanaRpc,
createSolanaRpcSubscriptions,
} from "@solana/kit";
const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
const rpcSubscriptions = createSolanaRpcSubscriptions("wss://api.mainnet-beta.solana.com");
const signer = await createKeyPairSignerFromBytes(secretKeyBytes);
const client = new Doppler(rpc, rpcSubscriptions, signer, {
programId: address(PROGRAM_ID),
admin: address(ADMIN),
});Fetch an Oracle
const oracle = await client.fetchOracle(oracleAddress, priceFeedSerializer);
if (!oracle) {
throw new Error("Oracle account not found");
}
console.log(oracle.sequence);
console.log(oracle.payload.price);Update an Oracle
const signature = await client.updateOracle(
oracleAddress,
{
sequence: BigInt(Date.now()),
payload: {
price: 42_000_000n,
},
},
priceFeedSerializer,
1_000n,
);
console.log(signature);For custom transaction composition, use the builder:
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
const message = client
.createTransactionBuilder()
.addOracleUpdate(
oracleAddress,
{
sequence: 123n,
payload: { price: 42_000_000n },
},
priceFeedSerializer,
)
.withUnitPrice(1_000n)
.buildMessage(latestBlockhash);