Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transferring ERC721 Tokens using Python/Web3.py

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.

like image 846
donny90210 Avatar asked Jun 21 '26 10:06

donny90210


1 Answers

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)
like image 129
donny90210 Avatar answered Jun 23 '26 23:06

donny90210



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!