curio-wrapper-truffle/scripts/transfer-wrapped.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-01-30 19:33:15 +00:00
const Wrapper = artifacts.require("CurioERC1155Wrapper");
module.exports = async (callback) => {
const nftId1 = parseInt(process.argv[6]);
const quantity1 = BigInt(process.argv[7]);
const to = process.argv[8];
if (/0x[0-9a-fA-F]{40}/.test(to)) {
const wrapper = await Wrapper.deployed();
const [account,] = await web3.eth.getAccounts();
2023-01-30 20:33:49 +00:00
const from = process.argv[9] ? process.argv[9] : account;
if (from !== account) {
console.log(`Overrode from address`);
const approved = await wrapper.isApprovedForAll(from, account);
console.log(`Approved? ${approved ? "yes" : "no"}`);
}
const currentBalance = BigInt(await wrapper.balanceOf(from, nftId1));
2023-01-30 19:33:15 +00:00
console.log(`Current balance: ${currentBalance}`);
if (currentBalance >= quantity1) {
console.log("Executing transfer transaction...");
try {
2023-01-30 20:33:49 +00:00
const result = await wrapper.safeTransferFrom(from, to, nftId1, quantity1.toString(), []);
2023-01-30 19:33:15 +00:00
console.log(`Transaction: ${result.tx}`);
}
catch (e) {
console.error(`FAILED: ${e}`);
}
}
else {
console.error("Insufficient balance");
}
}
callback();
}