Created
May 3, 2024 20:48
-
-
Save thetafferboy/ea064c22cbab53e6590e77c016b38375 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from web3 import Web3 | |
import json | |
infura_url = 'https://mainnet.infura.io/v3/your_project_id' | |
web3 = Web3(Web3.HTTPProvider(infura_url)) | |
if not web3.isConnected(): | |
print("Failed to connect to Ethereum network!") | |
exit() | |
contract_address = 'your_contract_address' | |
with open('URLCountryNFT.json') as f: | |
contract_abi = json.load(f) | |
contract = web3.eth.contract(address=contract_address, abi=contract_abi) | |
wallet_address = 'your_wallet_address' | |
wallet_private_key = 'your_wallet_private_key' | |
def mint_nft(recipient_address, token_uri): | |
nonce = web3.eth.getTransactionCount(wallet_address) | |
tx = contract.functions.mintNFT(recipient_address, token_uri).buildTransaction({ | |
'chainId': 1, | |
'gas': 2000000, | |
'gasPrice': web3.toWei('50', 'gwei'), | |
'nonce': nonce, | |
}) | |
signed_tx = web3.eth.account.sign_transaction(tx, wallet_private_key) | |
tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction) | |
print(f"Transaction hash: {tx_hash.hex()}") | |
recipient = 'recipient_ethereum_address' | |
token_uri = 'https://gateway.ipfs.io/ipfs/your_token_uri' | |
mint_nft(recipient, token_uri) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment