I want to transfer an nft from a 'AdminWallet' to a user with js. I have a AdminWallet that has all the nft's in it. Now I want users to be able to claim them with a press of a button.
I am using js code to accomplish this.
I have the following code:
const tx = {
from: PUBLIC_KEY,
to: user_address,
nonce: nonce,
gas: 500000,
data: contract.methods.safeTransferFrom(PUBLIC_KEY, user_address, "1").encodeABI(),
chain: "rinkeby",
hardfork: "petersburg"
}
const signPromise = web3.eth.accounts.signTransaction(tx, PRIVATE_KEY)
signPromise
.then((signedTx) => {
web3.eth.sendSignedTransaction(
signedTx.rawTransaction,
function(err, hash) {
if (!err) {
console.log(
"The hash of your transaction is: ",
hash,
)
} else {
console.log(
"Something went wrong when submitting your transaction:",
err
)
}
}
)
})
.catch((err) => {
console.log(" Promise failed:", err)
})
So what I am trying to do here is send an nft with tokenid '1' from the 'AdminWallet' on the address of PUBLIC_KEY to the user_address.
If I would do it without the signtransaction(), I would call the following:
contract.methods.safeTransferFrom(PUBLIC_KEY, user_address, "1").send({ from: PUBLIC_KEY})
From what I could find the signTransaction() calls the .Call() of the tx data. If I want to transfer the nft with my original way I have to call the .send() function.
Is there anyway to call the .send() function to sign the automatically sign the transaction?