let approved = await $contracts.nft.methods.isApprovedForAll($selectedAccount, sendit).call();
let approved = await $contracts.nft.methods.isApprovedForAll($selectedAccount, sendit).call();
if (!approved) {
if (!approved) {
errorMessage = 'SendIt requires approval to bulk transfer tokens; click the "Approve" button below';
errorMessage = 'SendIt requires approval to bulk transfer tokens; click the "Approve" button below';
checksPending = false;
contractApproved = false;
contractApproved = false;
return;
return;
}
}
} catch {
} catch {
errorMessage = 'Unable to check contract approvals';
errorMessage = 'Unable to check contract approvals';
checksPending = false;
return;
return;
}
}
// Check gas consumption forecasts
// Show gas consumption forecasts
await estimateGas(recipients, tokenIds);
await estimateGas(recipients, tokenIds);
// Show results
checked = true;
}
}
async function estimateCBT(recipients, tokens) {
async function estimateCBT(recipients, tokens) {
@ -138,14 +153,29 @@
if (recipients.length != tokens.length) {errorMessage='Invalid recipient/token IDs provided; please review';return;}
if (recipients.length != tokens.length) {errorMessage='Invalid recipient/token IDs provided; please review';return;}
await estimateCBT(recipients, tokens);
await estimateCBT(recipients, tokens);
await estimateSTF(recipients, tokens);
await estimateSTF(recipients, tokens);
// let gasPrice = await $web3.eth.getGasPrice();
let gasPrice = await $web3.eth.getGasPrice();
let gasPrice = 20000000000;
// let gasPrice = 50000000000;
let gasCostEth = await $web3.utils.fromWei((gasPrice * gasLimit).toString());
let gasPriceGwei = await $web3.utils.fromWei(gasPrice.toString(), 'gwei');
let gasCostWei = gasPrice * gasLimit;
let gasCostEth = await $web3.utils.fromWei(gasCostWei.toString());
let feeWei = await $contracts.sendit.methods.usageFee().call();
let feeWei = await $contracts.sendit.methods.usageFee().call();
let totalFeeWei = feeWei * recipients.length;
let totalFeeWei = feeWei * recipients.length;
let totalFeeEth = $web3.utils.fromWei(totalFeeWei.toString());
let si_gasCostWei = gasPrice * si_gasLimit + totalFeeWei;
let si_gasCostWei = gasPrice * si_gasLimit + totalFeeWei;
let si_gasCostEth = await $web3.utils.fromWei(si_gasCostWei.toString());
let si_gasCostEth = await $web3.utils.fromWei(si_gasCostWei.toString());
gasCalculation = `Transferring each token individual would require ${gasLimit} gas (${gasCostEth} Ξ). SendIt can do it for ${si_gasLimit} gas + a fee (${si_gasCostEth} Ξ).`;
let diffWei = gasCostWei - si_gasCostWei;
let diffEth = await $web3.utils.fromWei(diffWei.toString());
let diffPerc = 100 - ((si_gasCostWei / gasCostWei) * 100);
gasCalculation.push(`Current network gas price is ~${gasPriceGwei} gwei.`);
gasCalculation.push(`Transferring ${recipients.length} tokens individually would cost ~${gasCostEth} Ξ (${gasLimit} gas).`);
gasCalculation.push(`SendIt can bulk transfer ${recipients.length} tokens for ${si_gasCostEth} Ξ (${si_gasLimit} gas + a small fee of ${totalFeeEth} Ξ).`);
if (diffPerc <0){
gasCalculation.push(`That is an additional cost of ${diffEth*-1} Ξ to transfer in one go to save you the time`);
} else {
gasCalculation.push(`That is a savings of ${diffEth} Ξ (saved ~${Math.round(diffPerc)}%)`);