Skip to content
Open
Changes from all commits
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
11 changes: 5 additions & 6 deletions examples/p-chain/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { pvmapi } from '../chain_apis';
import { getChainIdFromContext } from '../utils/getChainIdFromContext';

const P_CHAIN_ADDRESS = process.env.P_CHAIN_ADDRESS;
const X_CHAIN_ADDRESS = process.env.X_CHAIN_ADDRESS;
const PRIVATE_KEY = process.env.PRIVATE_KEY;

const main = async () => {
if (!P_CHAIN_ADDRESS || !X_CHAIN_ADDRESS || !PRIVATE_KEY) {
const main = async (destinationChain: 'C' | 'X') => {
if (!P_CHAIN_ADDRESS || !PRIVATE_KEY) {
throw new Error('Missing environment variable(s).');
}

Expand All @@ -23,12 +22,12 @@ const main = async () => {

const tx = newExportTx(
context,
getChainIdFromContext('X', context),
getChainIdFromContext(destinationChain, context),
[bech32ToBytes(P_CHAIN_ADDRESS)],
utxos,
[
TransferableOutput.fromNative(context.avaxAssetID, BigInt(0.1 * 1e9), [
bech32ToBytes(X_CHAIN_ADDRESS),
bech32ToBytes(P_CHAIN_ADDRESS),
]),
],
);
Expand All @@ -41,4 +40,4 @@ const main = async () => {
return pvmapi.issueSignedTx(tx.getSignedTx());
};

main().then(console.log);
main('C').then(console.log);