@ -5,34 +5,39 @@
import IERC1155 from '@openzeppelin/contracts/build/contracts/IERC1155.json';
import IERC1155 from '@openzeppelin/contracts/build/contracts/IERC1155.json';
import SendIt from './lib/sendit.json';
import SendIt from './lib/sendit.json';
const sendit = '0x0165878A594ca255338adfa4d48449f69242Eb8F';
let errorMessage = '';
let errorMessage = '';
let successMessage = '';
let successMessage = '';
let contractAddress = '';
let contractAddress = '';
let contractApproved = true;
let contractApproved = true;
let checked = false;
let checked = false;
let gasCalculation = '';
let selectedStandard = 1;
let selectedStandard = 1;
let tokenStandards = [
let tokenStandards = [
{ id : 1 , text : 'ERC-721' } ,
{ id : 1 , text : 'ERC-721' } ,
{ id : 2 , text : 'ERC-1155' }
{ id : 2 , text : 'ERC-1155' }
]
]
// 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9
const sendit = '0x0165878A594ca255338adfa4d48449f69242Eb8F';
// const to = '0x7c83E906aDD18C093B4B01ED40b6BCb25d348ED9';
let amt = 10;
let amt = 10;
let gasLimit = 0;
let gasLimit = 0;
let si_gasLimit = 0;
let si_gasLimit = 0;
// evm.attachContract('nft', contractAddress, IERC721.abi);
evm.attachContract('sendit', sendit, SendIt.abi);
// evm.attachContract('sendit', sendit, SendIt.abi);
const approveSendIt = async () => {
const approveSendIt = async () => {
await $contracts.nft.methods.setApprovalForAll(sendit, true).send({ from : $selectedAccount } );
await $contracts.nft.methods.setApprovalForAll(sendit, true).send({ from : $selectedAccount } );
}
}
const isApproved = async () => {
return await $contracts.nft.methods.isApprovedForAll($selectedAccount, sendit).call({ from : $selectedAccount } );
// if (!i) {
// await $contracts.nft.methods.setApprovalForAll(sendit, true).send({ from : $selectedAccount } );
// }
}
const performCheck = async () => {
const performCheck = async () => {
let tokenIds = [];
let tokenIds = [];
let recipients = [];
errorMessage = '';
errorMessage = '';
// Determine ABI
// Determine ABI
@ -50,8 +55,6 @@
return;
return;
}
}
// Check textarea syntax
// Check textarea syntax
let info = document.getElementById('recipientInfo').value;
let info = document.getElementById('recipientInfo').value;
let lines = info.split(/(\s+)/);
let lines = info.split(/(\s+)/);
@ -62,7 +65,8 @@
let recipient = line[0];
let recipient = line[0];
let tokenId = line[1];
let tokenId = line[1];
try {
try {
$web3.utils.toChecksumAddress(recipient)
$web3.utils.toChecksumAddress(recipient);
recipients.push(recipient);
} catch {
} catch {
errorMessage = `Invalid recipient address supplied (line ${ i + 1 } )`;
errorMessage = `Invalid recipient address supplied (line ${ i + 1 } )`;
return;
return;
@ -90,11 +94,10 @@
return;
return;
}
}
}
}
}
}
}
}
// Check approval on the contract
// Check approval on the contract
try {
try {
let approved = await $contracts.nft.methods.isApprovedForAll($selectedAccount, sendit).call();
let approved = await $contracts.nft.methods.isApprovedForAll($selectedAccount, sendit).call();
@ -107,41 +110,38 @@
errorMessage = 'Unable to check contract approvals';
errorMessage = 'Unable to check contract approvals';
return;
return;
}
}
// Check gas consumption forecasts
// Check gas consumption forecasts
await estimateGas(recipients, tokenIds);
// Show results
// Show results
}
}
// const estimateCBT = async () => {
async function estimateCBT(recipients, tokens) {
// si_gasLimit = 0;
si_gasLimit = 0;
// let tokenIndexes = [];
await $contracts.sendit.methods.contractBulkTransfer(contractAddress, tokens, recipients, false).estimateGas({ from : $selectedAccount } , function(err, gas){
// let recipients = [];
si_gasLimit += gas;
// for (let i = 0; i < amt ; i ++) {
});
// tokenIndexes[i] = i + 1;
}
// recipients[i] = to;
// }
async function estimateSTF(recipients, tokens) {
// let i = await $contracts.nft.methods.isApprovedForAll($selectedAccount, sendit).call({ from : $selectedAccount } );
gasLimit = 0;
// if (!i) {
for (let i = 0; i < recipients.length ; i ++) {
// await $contracts.nft.methods.setApprovalForAll(sendit, true).send({ from : $selectedAccount } );
await $contracts.nft.methods.safeTransferFrom($selectedAccount, recipients[i], tokens[i]).estimateGas({ from : $selectedAccount } , function(err, gas){
// }
gasLimit += gas;
// await $contracts.sendit.methods.contractBulkTransfer(nft, tokenIndexes, recipients, false).estimateGas({ from : $selectedAccount } , function(err, gas){
});
// si_gasLimit += gas;
}
// });
}
// }
async function estimateGas(recipients, tokens) {
// const estimateSTF = async () => {
if (recipients.length != tokens.length) { errorMessage = 'Invalid recipient/token IDs provided; please review' ; return ; }
// gasLimit = 0;
await estimateCBT(recipients, tokens);
// for (let i = 0; i < amt ; i ++) {
await estimateSTF(recipients, tokens);
// await $contracts.nft.methods.safeTransferFrom($selectedAccount, to, i + 1).estimateGas({ from : $selectedAccount } , function(err, gas){
let gasPrice = await $web3.eth.getGasPrice();
// gasLimit += gas;
let gasCostEth = await $web3.utils.fromWei((gasPrice * gasLimit).toString());
// });
let si_gasCostEth = await $web3.utils.fromWei((gasPrice * si_gasLimit).toString());
// }
gasCalculation = `Transferring each token individual would require ${ gasLimit } gas (${ gasCostEth } Ξ). SendIt can do it for ${ si_gasLimit } gas (${ si_gasCostEth } Ξ).`;
// }
}
// function estimateGas() {
// estimateCBT();
// estimateSTF();
// }
< / script >
< / script >
@ -180,6 +180,10 @@
< / form >
< / form >
{ /if }
{ /if }
{ #if gasCalculation }
< p > { gasCalculation } </ p >
{ /if }
{ #if errorMessage }
{ #if errorMessage }
< p id = "errorMessage" > { errorMessage } </ p >
< p id = "errorMessage" > { errorMessage } </ p >
{ /if }
{ /if }