Skip to content

Instantly share code, notes, and snippets.

@KarthickNcog
Created October 6, 2023 06:30
Show Gist options
  • Select an option

  • Save KarthickNcog/71494a9ece00f9b33280722530f2ef95 to your computer and use it in GitHub Desktop.

Select an option

Save KarthickNcog/71494a9ece00f9b33280722530f2ef95 to your computer and use it in GitHub Desktop.
const Web3 = require('web3');
const web3 = new Web3('YOUR_ETHEREUM_NODE_URL');
// The sender's private key (keep this secure)
const senderPrivateKey = 'YOUR_SENDER_PRIVATE_KEY';
// Connect to sender's wallet
const senderAccount = web3.eth.accounts.privateKeyToAccount(senderPrivateKey);
// NFT contract address and ABI
const nftContractAddress = 'YOUR_NFT_CONTRACT_ADDRESS';
const nftContractABI = [...]; // Replace with the actual ABI
// NFT token ID and recipient's address
const tokenId = 123;
const recipientAddress = '0xRecipientAddress';
const nftContract = new web3.eth.Contract(nftContractABI, nftContractAddress);
// Create the transaction to transfer the NFT
const data = nftContract.methods.transferFrom(senderAccount.address, recipientAddress, tokenId).encodeABI();
web3.eth.sendTransaction({
from: senderAccount.address,
to: nftContractAddress,
gas: 200000, // Adjust gas limit as needed
gasPrice: '1000000000', // Adjust gas price as needed
data: data,
})
.then((receipt) => {
console.log('Transaction receipt:', receipt);
})
.catch((error) => {
console.error('Error transferring NFT:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment