I'm trying to send an ERC1155 to a Safe Wallet from an EOA address, and so far, I have been unsuccessful. Here's the code I'm using:
async function main() {
try {
// setup
const provider = new HDWalletProvider(mnemonic, providerURL)
const web3 = new Web3(provider)
const abi = JSON.parse(fs.readFileSync(abipath).toString())
const contract = new web3.eth.Contract(abi.abi, contractAddress)
// get gas estimate
const gasPrice = await web3.eth.getGasPrice()
const estimatedGas = await contract.methods.safeTransferFrom(
fromAddress,
toAddress,
tokenId,
2,
'0x'
)
.estimateGas({ from: fromAddress })
logger.debug(`gasPrice ${gasPrice} estimatedGas ${estimatedGas}`)
// initiate transfer
const sendResult = await contract.methods.safeTransferFrom(
fromAddress,
toAddress,
tokenId,
2,
'0x'
)
.send({ from: fromAddress, gas: estimatedGas, gasPrice: gasPrice })
logger.info(`sendResult ${JSON.stringify(sendResult, null, 2)}`)
} catch (e) {
logger.error(`error ${e} \n\n ${JSON.stringify(e, null, 2)}`, e)
}
}
I get this error from the estimateGas
line:
{
"code": -32000,
"message": "execution reverted"
} { code: -32000, message: 'execution reverted' }
Any idea what I'm doing wrong?