A token transfer operation is actually a smart contract method call, which is a bit different than simple ETH sending:
- you'll have to fill the
data:
portion of the tx with the info related to the smart contract method call (more below)
- the
from:
address is the same as in a normal ETH send operation
- the
to:
address is the address of the smart contract, not the address of the recipient
- the
value:
field is 0
How to fill the data
field. The example is done using web3js
v1.0+.
You'll need to have:
- your smart contract's ABI. Let's say you store that in variable
ctrABI
- an instance of Web3. Let's say that's stored in variable
web3
the address where your ERC721 smart contract is deployed - ctrAddress
const ctrInstance = new web3.eth.Contract(JSON.parse(ctrABI), ctrAddress)
const dataField = await ctrInstance.methods.transfer(addrTo, tokenId ).encodeABI();
And then proceed to build your transaction:
const txParams = {
nonce: '0x6', // Replace by nonce for your account on geth node
gasPrice: '0x09184e72a000',
gasLimit: '0x30000', //modify accordingly
to: ctrAddress,
data: dataField,
value: '0x00'
};