Last active
May 4, 2020 07:34
-
-
Save nichanank/e59b6827d63ac09f695bce946b2e1d4c to your computer and use it in GitHub Desktop.
Creating a payment stream with Sablier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// yarn add bignumber.js | |
// import BigNumber from 'bignumber.js' | |
// BigNumber.config({ EXPONENTIAL_AT: 30 }) <--- add this after your imports, it will prevent the number from being formatted like "1e+21" | |
// call this when the user presses the "Create Stream" button | |
const sablier = new ethers.Contract(addresses[chainId].sablier, abis.sablier, getProviderOrSigner(library, account)) | |
let convertedStartTime = Math.round(startTime.getTime() / 1000) | |
let convertedStopTime = Math.round(stopTime.getTime() / 1000) | |
let convertedDeposit = new BigNumber(deposit).multipliedBy(10 ** 18).toFixed(0) | |
let remainder = new BigNumber(convertedDeposit) % (convertedStopTime - convertedStartTime) | |
let amountToDeposit = new BigNumber(convertedDeposit).minus(remainder).toString() | |
const token = new ethers.Contract("0xc3dbf84abb494ce5199d5d4d815b10ec29529ff8", abis.erc20, getProviderOrSigner(library, account)); | |
const approveTx = await token.approve(sablier.address, amountToDeposit); | |
await approveTx.wait(); | |
const createStreamTx = await sablier.createStream(recipient, amountToDeposit, token.address, convertedStartTime, convertedStopTime); | |
await createStreamTx.wait(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment