Utilities
Constants
BigGas
BigGas
Following up your function arguments with BigGas to set a high gas limit and price so that your transactions are more likely to execute. You can change these values within the ReaperSDK.js file.
reaper.BigGas === { gasPrice: 100000000000, gasLimit: 5000000 }
For example:
Addresses.json
Addresses.json
Addresses.json contains the addresses of many popular contracts on the Fantom network, and it's easy to add more. Simply import it from the directory's root with a require statement and use dot notation to reference the addresses within. The object is separated by token addresses, testnet contract addresses, and mainnet contract addresses.
Import them each with the following:
const { tokens, testnet, mainnet } = require("../Addresses.json");
Contract Instantiation
You can create a contract interface and attach it to an address in a single function call with our createContract function. Just make sure you've already compiled your contracts with Hardhat. Refer to the contract title as a string for the first argument and use the target address as the second like so:
reaper.createContract(contractTitle: string, contractAddress: string);
Decimal Formatting
Formatting human-readable inputs with reaper.parseToken()
reaper.parseToken()
You can turn floating point inputs of any type into a blockchain-readable BigNumber value in parts-per notation with 18 decimal places. An optional tokenAddress argument will automatically format your input using the correct amount of decimal places, such as 6 for USDC or 8 for BTC.
reaper.parseToken(amount:string or number, { tokenAddress: string });
Formatting big number outputs with reaper.formatToken()
reaper.formatToken()
Using the format() function, you can turn any bigNumber-ish value into a human readable fixed-point integer. Using the optional tokenAddress input will allow the function to automatically determine the token's decimals and adjust accordingly. See an example of this below - the function automatically adjusts to USDC's 6 decimals and BTC's 8 decimals.
reaper.formatToken(amount:BigNumber, { tokenAddress: string });
Pausing Execution
Due to its unpredictable nature, blockchain development can be a tricky beast. On Fantom, you may find your transactions failing due to being sent too soon after the preceding transaction. You may also want to manage transaction timing off-chain when running scripts or simulations. You can handle all of this with Reaper's sleep function.
reaper.sleep(miliseconds:uint)
Getting a timestamp
Getting the block.timestamp value in Javascript can be kind of tricky, so Reaper took care of that for you. It's so simple I'm not even going to include an example >:^)
reaper.getTimestamp() => timestamp:uint
Last updated