Transferring ERC721 Tokens using Python/Web3.py

1.6k views Asked by At

I can not for the life of me find any article on the entire interweb that talks about using web3.py to transfer ERC-721 tokens between wallets. Minting, yes all day long, airdrop yes all day long, but wallet to wallet transfer, nope. Am I missing something here, is it not possible? Why is there such a lack of dialogue on this matter. Anyways, if you could point me in the right direction or answer my question, that would be amazing. I would tell you what I have tried so far, but the answer is nothing because I do not even know where to start. As far as I got was ...

contract_call = contract.functions.transfer(destination_address, value)
unsigned_txn = contract_call.buildTransaction({'chainId': 1, 'gasPrice': 
w3.toWei(100, 'gwei')})

But this does not appear to be what I am looking for.

1

There are 1 answers

0
donny90210 On

After way to much reading I finally got it done, I hope this helps somebody one day.

The problem here is almost anywhere there is documentation it says to use transact( not buildTransaction when buildTransaction IS the correct way of doing this.

Make sure you have your contract initialised properly

transferFrom arguments FROM, TO, TOKEN_ID

FROM being the wallet that owns the NFT. TO who you are transferring the NFT to. PRIVATE_KEY being the key to the FROM wallet.

mint_txn = NFT_CONTRACT.functions.transferFrom(FROM, TO, 8).buildTransaction(
    {
        'from': FROM,
        'nonce': nonce,
        'gas': 1000000,
        'gasPrice': w3.toWei("70", "gwei"),

    }
)

signed_txn = w3.eth.account.sign_transaction(mint_txn, 
private_key=PRIVATE_KEY)
w3.eth.send_raw_transaction(signed_txn.rawTransaction)