With the information of the previous step, you can approve and purchase executions to be able to schedule them in the future.
If the token is one of the supported ERC-677 you don’t need to approve before purchasing. You can pass the list of supported tokens using
config.supportedERC677Tokens
import { RIFScheduler } from "@rsksmart/rif-scheduler-sdk";
const config = {
contractAddress: serviceProviderContractAddress,
providerOrSigner: signer
}
const rifScheduler = new RIFScheduler(config);
const executionsQuantity = 2;
const plan = rifScheduler.getPlan(planIndex)
const totalAmount = plan.pricePerExecution.mul(executionsQuantity)
// First, check if token requires approval
if (plan.token.needsApproval(totalAmount))
await plan.token.approve(totalAmount)
const purchaseTransaction = await plan.purchase(executionsQuantity)
await purchaseTransaction.wait(12)
It will return how many executions you have left.
You will need to purchase some executions if you want to schedule something (see previous step).
This is an optional step, but it is useful because it will give you feedback that everything you have done in the previous steps was correct.
import { RIFScheduler } from "@rsksmart/rif-scheduler-sdk";
const config = {
contractAddress: serviceProviderContractAddress,
providerOrSigner: signer
}
const rifScheduler = new RIFScheduler(config);
const plan = rifScheduler.getPlan(planIndex)
const remainingExecutions = await plan.getRemainingExecutions()
// 2
What you can do with this sdk?
Go to top