# Example Usage

## Remote Signing

The below example code displays the usage of `customSigner` to remotely sign a transaction that was generated by Anchor Earn.

For demonstration purposes, implementation of `customSigner` was done using Terra.js. For real usage `customSigner` should be connected with a remote signing solution used by the integrator (e.g. Ledger Hardware Wallet, Custodian APIs).

```javascript
const anchorEarn = new AnchorEarn({
  chain: CHAINS.TERRA,
  network: NETWORKS.BOMBAY_12,
  mnemonic:
    '...',
});

// customSigner signs the generated unsigned tx
const customSigner = async (tx: Msg[]) => {
  const account = new MnemonicKey({
  mnemonic:
    '...',
  });

  const wallet = new Wallet(
    new LCDClient({
      URL: 'https://bombay-lcd.terra.dev',
      chainID: 'bombay-12',
    }),
    account,
  );

  return await wallet.createAndSignTx({
    msgs: tx,
    gasAdjustment: 2,
    gasPrices: { uusd: 0.15 },
  });
};

await anchorEarn.deposit({
  amount: '0.01',
  currency: DENOMS.UST,
  log: (data) => {
    console.log(data);
  },
  customSigner: customSigner,
});
```

## Remote Signing & Broadcasting

The below example code displays the usage of `customBroadcaster` to remotely sign and broadcast a transaction that was generated by Anchor Earn.

For demonstration purposes, implementation of `customBroadcaster` was done using Terra.js. For real usage `customBroadcaster` should be connected with a remote signing solution used by the integrator (e.g. Web Wallet Extension).

```javascript
const anchorEarn = new AnchorEarn({
  chain: CHAINS.TERRA,
  network: NETWORKS.BOMBAY_12,
  mnemonic:
    '...',
});

// customBroadcaster signs and broadcasts the generated unsigned tx
const customBroadcaster = async (tx: Msg[]) => {
  const lcd = new LCDClient({
    URL: 'https://bombay-lcd.terra.dev',
    chainID: 'bombay-12',
  });

  const wallet = new Wallet(
    lcd,
    new MnemonicKey({
    mnemonic:
      '...',
    }),
  );

  const signedTx = await wallet.createAndSignTx({
    msgs: tx,
    gasAdjustment: 2,
    gasPrices: { uusd: 0.15 },
  });

  return lcd.tx.broadcastSync(signedTx).then((result) => {
    return result.txhash;
  });
};

await anchorEarn.withdraw({
  amount: '0.01',
  currency: DENOMS.AUST,
  log: (data) => {
    console.log(data);
  },
  customBroadcaster: customBroadcaster
});
```

## Logging Transaction Progress

The below example code displays the usage of `loggable` to check on request progresses that were generated by Anchor Earn.

```javascript
const deposit = await anchorEarn.deposit({
  amount: '...',
  currency: DENOMS.UST,
  log: (data) => {
    console.log(data);
  }
});
```


---

# 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://docs.anchorprotocol.com/anchor-2/developers-earn/example-usage.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.
