Anchor Protocol
  • Home
  • Security
  • Protocol
    • Overview
    • Bonded Assets (bAssets)
      • Bonded Luna (bLuna)
      • Bonded ETH (bETH)
    • Money Market
      • Deposit Rate Subsidization
    • Loan Liquidation
    • Anchor Token (ANC)
    • Anchor Governance
      • Modify Collateral Attributes
      • Modify Market Parameters
      • Modify Liquidation Parameters
      • Modify ANC Parameters
      • Modify Governance Parameters
      • Modify Borrow Interest
      • Modify ANC Distribution
      • Community Grants
      • Text Proposal
  • User Guide
    • Interchain Transfers
    • WebApp
      • EARN
      • BORROW
      • bASSET [bLUNA]
      • bASSET [bETH]
      • GOVERN
        • ANC - UST LP Staking
        • Anchor Governance Staking
        • Claiming ANC Rewards
        • Creating and voting on proposals
  • EthAnchor
    • EthAnchor
    • EthAnchor Contracts
      • Deployed Contracts
      • Router
      • ConversionPool
      • ExchangeRateFeeder
    • Fees
  • Developers - Earn
    • Anchor Earn SDK
    • Example Usage
    • Appendix
  • xAnchor
    • xAnchor
    • xAnchor Contracts
    • xAnchor Bridge (EVM Chains)
    • xAnchor Terra-side Contracts
      • xAnchor Core
      • xAnchor Wormhole Bridge
      • Address Proxy
  • Developers - Terra
    • Anchor.js
    • AnchorCLI
  • Smart Contracts
    • Deployed Contracts
    • bLuna
      • Hub
      • Reward
      • Rewards Dispatcher
      • Validators Registry
      • Airdrop Registry
      • Tokens: bLuna and stLuna
    • bETH
      • Reward
      • Token
      • Converter
    • Money Market
      • Overseer
      • Market
      • Custody [bLUNA]
      • Custody [bETH]
      • Interest Model
      • Distribution Model
      • Oracle
    • Liquidation
      • Liquidation Contract
      • Liquidation Queue Contract
    • Anchor Token (ANC)
      • Gov
      • Staking
      • Community
      • Collector
      • Distributor
  • Developers - Ethereum [Legacy]
    • EthAnchor
    • EthAnchor Account Contract
    • EthAnchor API
      • Getting Market Information
      • Depositing Stablecoins
      • Redeeming Stablecoins
    • Fees
  • External Resources
    • Anchor WebApp
    • Anchor Protocol GitHub
    • Terra Blockchain
Powered by GitBook
On this page
  • Remote Signing
  • Remote Signing & Broadcasting
  • Logging Transaction Progress

Was this helpful?

  1. Developers - Earn

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).

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).

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.

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

Last updated 3 years ago

Was this helpful?