Skip to content

Commit

Permalink
feat: add stake example (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
gidonkatten authored Jan 23, 2025
1 parent 8514c04 commit bb0d94d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions examples/xalgo/stake.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { assignGroupID } from "algosdk";

import {
getConsensusState,
prefixWithOpUp,
prepareImmediateStakeTransactions,
TestnetConsensusConfig,
TestnetOpUp,
} from "../../src";
import { algodClient, sender } from "../config";

async function main() {
const opup = TestnetOpUp;
const consensusConfig = TestnetConsensusConfig;

// retrieve params and consensus state
const params = await algodClient.getTransactionParams().do();
const consensusState = await getConsensusState(algodClient, consensusConfig);

// stake 1 ALGO
const stakeAmount = 1e6;
const minReceivedAmount = 0;
let stakeTransactions = prepareImmediateStakeTransactions(
consensusConfig,
consensusState,
sender.addr,
sender.addr,
stakeAmount,
minReceivedAmount,
params,
);

// add additional opcode budget (if needed)
stakeTransactions = prefixWithOpUp(opup, sender.addr, stakeTransactions, 0, params);

// group, sign and submit
assignGroupID(stakeTransactions);
const signedTxns = stakeTransactions.map((txn) => txn.signTxn(sender.sk));
await algodClient.sendRawTransaction(signedTxns).do();
}

main().catch(console.error);
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"declarationDir": "dist/types",
"sourceMap": true
},
"include": ["src/**/*"]
"include": ["src/**/*", "examples/**/*"]
}

0 comments on commit bb0d94d

Please sign in to comment.