Skip to content
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

Implement IncreaseBalanceTx #888

Merged
merged 7 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions examples/p-chain/etna/convertSubnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const BALANCE_AVAX: number = 1;
* @param subnetId the ID of the subnet that is created via `createSubnetTx`.
* @returns The resulting transaction's ID.
*/
const convertSubnetTxExmaple = async () => {
const convertSubnetTxExample = async () => {
erictaylor marked this conversation as resolved.
Show resolved Hide resolved
const {
AVAX_PUBLIC_URL,
P_CHAIN_ADDRESS,
Expand Down Expand Up @@ -74,4 +74,4 @@ const convertSubnetTxExmaple = async () => {
return pvmApi.issueSignedTx(tx.getSignedTx());
};

convertSubnetTxExmaple().then(console.log);
convertSubnetTxExample().then(console.log);
35 changes: 35 additions & 0 deletions examples/p-chain/etna/increaseBalanceTx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { addTxSignatures, pvm, utils } from '../../../src';
import { setupEtnaExample } from './utils/etna-helper';
import { getEnvVars } from '../../utils/getEnvVars';

const BALANCE_AVAX: number = 1;
const VALIDATION_ID: string = '';

const increaseBalanceTx = async () => {
const { AVAX_PUBLIC_URL, P_CHAIN_ADDRESS, PRIVATE_KEY } = getEnvVars();
const { context, feeState, pvmApi } = await setupEtnaExample(AVAX_PUBLIC_URL);

const { utxos } = await pvmApi.getUTXOs({ addresses: [P_CHAIN_ADDRESS] });

const testPAddr = utils.bech32ToBytes(P_CHAIN_ADDRESS);

const unsignedTx = pvm.e.newIncreaseBalanceTx(
{
balance: BigInt(BALANCE_AVAX * 1e9),
feeState,
fromAddressesBytes: [testPAddr],
utxos,
validationId: VALIDATION_ID,
},
context,
);

await addTxSignatures({
unsignedTx,
privateKeys: [utils.hexToBuffer(PRIVATE_KEY)],
});

return pvmApi.issueSignedTx(unsignedTx.getSignedTx());
};

await increaseBalanceTx().then(console.log);
Loading