## About us
This is the free and open-source node.js SDK for expand.network, an adapter API service that offers one common gateway for various queries (read functions) and transactions (write functions) for all major blockchains and smart contract based protocols. We offer a single integration point for access to all of DeFi.
For details on the complete capabilities of the API, please refer to the categories section in [our technical documentation](https://docs.expand.network).
We currently support the following blockchains:
All transactions are securely signed on your end, so your private key remains with you and never comes to us over API. We do not hold your crypto at any point: Your keys, Your crypto. Our APIs are a one-stop-shop for you to make the enquiries and conduct the transactions as you want.
CT makes it easier to detect and prevent digital certificate fraud, thereby improving the security of internet connections.
In addition to implementing certificate transparency measures on our end, we highly recommend users to also consider implementing these measures for added security benefits.
A user's private key is stored securely in a digital wallet, and should never be shared with anyone as it provides full access and control over their digital assets.
It is highly recommended that users take necessary precautions to ensure the safety and confidentiality of their private keys, as we do not possess any access or control over them.
It is important for the user to safeguard both their data and workstation from potential risks such as spoofing, tampering, and other related threats.
It is important for the end user to connect to a secure network and ensure that they use only TLS 1.2 or a newer version for enhanced security to safeguard them from any kind of threats and attacks.
Sample code: Send one Wei from one public address to another public address. You need to use your private key to sign the transaction. The return value is the transaction hash (res).
Sample code: Approve 5 DAI (token ending in d0F),In this example, the "from" is the user address (ending in 006) and "to" is protocol address (ending in 056), so 5 DAI is approved from user address on the protocol address. User need to use private key to sign the transaction.
const { Wallet, prepareTransaction } = require('expand-network');
asyncfunctionapprove() {
const wallet = newWallet({ privateKey: 'YOUR_PRIVATE_KEY', xApiKey: 'YOUR_API_KEY' });
// Preparing transactionconst preparedTx = awaitprepareTransaction('https://api.expand.network/fungibletoken/approve', {
from: 'PUBLIC_ADDRESS',
to: 'PUBLIC_ADDRESS', // The spender's or contract's or router's address that needs to be approvedtokenAddress:"0x6B175474E89094C44Da98b954EedeAC495271d0F",
amount: "5000000000000000000",
gas: '100000',
chainId:"1"xApiKey: "YOUR_API_KEY"
});
// Signing transactionconst signedTx = await wallet.signTransaction(preparedTx);
//Sending transactionconst tx = await wallet.sendTransaction(signedTx);
console.log("Transaction Pending....", tx.data);
}
approve();
Sample code: Swap 5 DAI (token ending in d0F) with WETH (token ending in Cc2). In this example, the "to" and "from" are the same (ending in 006), so the swapped tokens will come back into the same address. Again, you need to use your private key to sign the transaction.
Sample Code: For the swap pair DAI <> WETH, find the best price on three different DEX protocols: Uniswap v2, v3, and Sushiswap. Whichever DEX has the best price, swap the DAI with WETH on that particular DEX.
const { Wallet, prepareTransaction } = require('expand-network');
constgetPrice = async(dexId) => {
config.params = {
dexId: dexId,
path: '0x6B175474E89094C44Da98b954EedeAC495271d0F' + ',' + '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
amountIn: amount
}
const response = await axios.get(baseUrl + '/dex/getprice/', config);
prices[dexId] = response.data.amountsOut[1];
}
constswap = async(dexId) => {
const wallet = newWallet({ privateKey: 'YOUR_PRIVATE_KEY', xApiKey: 'YOUR_API_KEY' });
const preparedTx = awaitprepareTransaction(baseUrl + '/dex/swap', {
dexId,
amountIn: amount,
amountOutMin: '0',
path: [ '0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' ],
to: 'PUBLIC_ADDRESS',
deadline: Date.now() + 60*60*20,
from: 'PUBLIC_ADDRESS',
gas: '229880',
xApiKey : 'YOUR_API_KEY'
});
// Signing transactionconst signedTx = await wallet.signTransaction(preparedTx);
//Sending transactionconst tx = await wallet.sendTransaction(signedTx);
console.log("Transaction Pending....", tx.data);
}
constbestBuy = async() => {
// Fetching price from Uniswap V2awaitgetPrice('1000');
// Fetching price from SushiswapawaitgetPrice('1100');
// Fetching price from Uniswap V3awaitgetPrice('1300');
var max = 0;
var maxDexId = 0;
for ( var dexId in prices ){
if ( Number(prices[dexId]) > max ) {
max = prices[dexId];
maxDexId = dexId;
}
}
console.log(`${maxDexId} gives the best swap price of ${max}`);
// Time to swap the tokensswap(maxDexId);
}
bestBuy();