Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-dev committed Nov 14, 2024
1 parent a8a1297 commit 3a809ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
33 changes: 27 additions & 6 deletions examples/with-ton/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import * as dotenv from "dotenv";
import * as path from "path";
import { TonClient, Address, beginCell, WalletContractV4, internal, storeMessageRelaxed, SendMode, Cell, storeMessage, external } from "@ton/ton";
import {
TonClient,
Address,
beginCell,
WalletContractV4,
internal,
storeMessageRelaxed,
SendMode,
Cell,
storeMessage,
external,
} from "@ton/ton";
import { input } from "@inquirer/prompts";
import { Turnkey } from "@turnkey/sdk-server";
import { bytesToHex } from "@noble/hashes/utils";
Expand Down Expand Up @@ -49,14 +60,17 @@ async function createWalletTransferV4WithTurnkey(args: {

const { r, s } = txSignResult;
const signatureBytes = Buffer.from(r + s, "hex");
const body = beginCell().storeBuffer(signatureBytes).storeBuilder(signingMessageBuilder).endCell();
const body = beginCell()
.storeBuffer(signatureBytes)
.storeBuilder(signingMessageBuilder)
.endCell();
return body;
}

async function externalTransaction(
client: TonClient,
address: Address,
init: { code: Cell | null, data: Cell | null } | null,
init: { code: Cell | null; data: Cell | null } | null,
body: Cell
) {
// Check if the contract needs initialization (init code/data)
Expand Down Expand Up @@ -96,15 +110,19 @@ async function main() {
const walletPublicKey = process.env.TON_PUBLIC_KEY!;

if (!walletAddress || !walletPublicKey) {
throw new Error("Please set your TON_ADDRESS and TON_PUBLIC_KEY in the .env.local file.");
throw new Error(
"Please set your TON_ADDRESS and TON_PUBLIC_KEY in the .env.local file."
);
}

console.log(`Using TON address: ${walletAddress}`);

const tonAddress = Address.parse(walletAddress);
let accountData = await client.getBalance(tonAddress).catch(() => null);
if (!accountData || BigInt(accountData) === 0n) {
console.log(`Your account does not exist or has zero balance. Fund your address ${walletAddress} to proceed.`);
console.log(
`Your account does not exist or has zero balance. Fund your address ${walletAddress} to proceed.`
);
process.exit(1);
}

Expand Down Expand Up @@ -138,7 +156,10 @@ async function main() {
});

// Check if the wallet is deployed, if not provide init data
const init = opened.init && !(await client.isContractDeployed(tonAddress)) ? opened.init : null;
const init =
opened.init && !(await client.isContractDeployed(tonAddress))
? opened.init
: null;

// Send the transaction using the external transaction logic
externalTransaction(client, tonAddress, init, body);
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a809ab

Please sign in to comment.