He acuñado algunos NFT en mar abierto. Estos están en la red Polygon Mumbai. Ahora quiero transferirlos al token a otras direcciones usando alchemy web3. Aquí está el código que estoy usando.
Nota : se supone que esto se ejecuta en la API tranquila de nodejs, por lo que no hay una billetera disponible, por eso estoy firmando manualmente la transacción.
async function main() { require('dotenv').config(); const { API_URL,API_URL_TEST, PRIVATE_KEY } = process.env; const { createAlchemyWeb3 } = require("@alch/alchemy-web3"); const web3 = createAlchemyWeb3(API_URL_TEST); const myAddress = '*************************' const nonce = await web3.eth.getTransactionCount(myAddress, 'latest'); const transaction = { //I believe transaction object is not correct, and I dont know what to put here 'asset': { 'tokenId': '******************************',//NFT token id in opensea }, 'gas': 53000, 'to': '***********************', //metamask address of the user which I want to send the NFT 'quantity': 1, 'nonce': nonce, } const signedTx = await web3.eth.accounts.signTransaction(transaction, PRIVATE_KEY); web3.eth.sendSignedTransaction(signedTx.rawTransaction, function(error, hash) { if (!error) { console.log("🎉 The hash of your transaction is: ", hash, "\n Check Alchemy's Mempool to view the status of your transaction!"); } else { console.log("❗Something went wrong while submitting your transaction:", error) } }); } main();Asumió que tiene Metamask instalado en su navegador y que el contrato inteligente NFT sigue el estándar ERC721
const { API_URL,API_URL_TEST, PRIVATE_KEY } = process.env; const { createAlchemyWeb3 } = require("@alch/alchemy-web3"); const {abi} = YOUR_CONTRACT_ABI const contract_address = CONTRACT ADDRESS require('dotenv').config(); async function main() { const web3 = createAlchemyWeb3(API_URL_TEST); web3.eth.getAccounts().then(accounts => { const account = account[0] const nameContract = web3.eth.Contract(abi, contract_address); nameContract.methods.transfer(account, ADDRESS_OF_WALLET_YOU_WANT_TO_SEND_TO, TOKEN_ID).send(); }) .catch(e => console.log(e)); } main();