# Safe Private Transfer

To make sure that you will not lose your funds because of any instability on your machine, use this pattern:

```javascript
import { TyphoonSDK } from 'typhoon-sdk'
import { RpcProvider, Account } from 'starknet';
import * as fs from 'fs';
import { readFile } from "fs/promises";

const provider = new RpcProvider({ nodeUrl: "https://starknet-mainnet.public.blastapi.io/rpc/v0_8" });
const sdk = new TyphoonSDK()
const STRK_ADDR = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
const amount = 110000000000000000000n // 110 STRK

// use the wallet account if you run in your frontend
const account = new Account(provider, "0xyouraddress", "0xprivkey"); 

// this function generates the calls to make a deposit
let calls = await sdk.generate_approve_and_deposit_calls(amount, STRK_ADDR)

// execute the deposit calls
const multiCall = await account.execute(calls);
// get the data for withdraw as json
const jsonString = JSON.stringify(
    {   "secrets": sdk.get_secrets(), 
        "nullifiers": sdk.get_nullifiers(), 
        "pools": sdk.get_pools(), 
        "txHash": multiCall.transaction_hash 
    }, null, 2); // The third argument adds indentation for readability

// Write the JSON string to a file
fs.writeFile('deposit-data.json', jsonString, 'utf8', (err) => {
        if (err) {
            console.error('An error occurred while writing JSON Object to File:', err);
       } else {
            console.log('JSON file has been saved.');
       }
});

await account.waitForTransaction(multiCall.transaction_hash);
```

The code above allows you to save the data needed for the withdraw, it means that the withdraw could be executed latter, like in the code bellow:

```javascript
import {TyphoonSDK} from 'typhoon-sdk'
import { readFile } from "fs/promises";

const jsonStrdata = await readFile('./deposit-data.json', "utf8");
let data = JSON.parse(data);
sdk.init(data.secrets, data.nullifiers, data.pools)
await sdk.withdraw(data.txHash, [recipient_addr]) 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://typhoon-2.gitbook.io/typhoon-docs/examples/safe-private-transfer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
