Skip to content

Commit

Permalink
chore: populate api path via env vars
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Belchior <[email protected]>
  • Loading branch information
rafaelbelchiorbd committed Aug 13, 2024
1 parent 263b418 commit 7743613
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
BLOCKDAEMON_API_KEY=
DEFI_API_BASE_PATH=https://svc.blockdaemon.com/defi
MNEMONIC=
LOG_LEVEL="DEBUG"
SENDER_ADDRESS=
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# defi-api-examples

This tool is a simple example app that leverages BD's DEFI API.
This repository comprise a set of scripts that leverages BD's DEFI API. The script collection guides the creation of an application that leverages the DEFI API and has cross-chain token transfer capabilities.

### Requirements
This is a Typescript project. Npm as package manager and node. Tested with npm v10.2.4, node 21.5.0. We recommend using [nvm](https://github.com/nvm-sh/nvm) for node version management.
Expand Down Expand Up @@ -28,4 +28,12 @@ This is a Typescript project. Npm as package manager and node. Tested with npm v
* `get-routes` (gets a set of routes that satisfy a swap);
* `get-tokens-by-tag` (gets the list of supported tokens by specified tag)
* `get-tokens` (gets the list of supported tokens)
* `sign-and-broadcast-transaction` (signs and broadcasts a transaction to the blockchain)
* `sign-and-broadcast-transaction` (signs and broadcasts a transaction to the blockchain).

### Common issues and Troubleshooting
For issues related to the code in this repository, please use the [issues tracker](https://github.com/Blockdaemon/defi-api-examples/issues).

### 👋 Need Further Help?

Contact us through [email]([email protected]) or our [support page](https://www.blockdaemon.com/support) for any issues, bugs, or assistance you may need.

4 changes: 2 additions & 2 deletions src/main/scripts/get-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ async function main() {
const api = new ExchangeApi(apiConfig);

const routeParameters: GetRoutesRequest = {
fromChain: "10", // Optimism
fromChain: "eip155:10", // Optimism
fromToken: "0x7f5c764cbc14f9669b88837ca1490cca17c31607", // USDC.e
fromAmount: "1000000",
toChain: "137", // Polygon
toChain: "eip:155137", // Polygon
toToken: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f", // USDT
fromAddress: polygonWallet.address,
toAddress: optimismWallet.address,
Expand Down
5 changes: 4 additions & 1 deletion src/main/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const log: log4js.Log4js = log4js.configure({
},
});

const DEFI_API_BASE_PATH =
process.env.DEFI_API_BASE_PATH || "https://svc.blockdaemon.com/defi";

export const API_KEY: string =
process.env.BLOCKDAEMON_API_KEY ||
(() => {
Expand Down Expand Up @@ -58,7 +61,7 @@ export const polygonWallet = Wallet.fromPhrase(mnemonic, polygonProvider);
export const optimismWallet = Wallet.fromPhrase(mnemonic, optimismProvider);

export const apiConfig = new Configuration({
basePath: "https://svc.blockdaemon.com/defi",
basePath: DEFI_API_BASE_PATH,
headers: {
authorization: `Bearer ${process.env.BLOCKDAEMON_API_KEY}`,
},
Expand Down

0 comments on commit 7743613

Please sign in to comment.