Created
May 3, 2024 20:47
-
-
Save thetafferboy/8f75b841830d7da5d299ad0af702a970 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 | |
# Connect to Ethereum network | |
infura_url = 'https://mainnet.infura.io/v3/your_project_id' | |
web3 = Web3(Web3.HTTPProvider(infura_url)) | |
# Check if connected to Ethereum | |
if not web3.isConnected(): | |
print("Failed to connect to Ethereum network!") | |
exit() | |
# Set up the contract | |
contract_address = 'your_contract_address' | |
with open('URLCountryNFT.json') as f: # Load the ABI from a JSON file | |
contract_abi = json.load(f) | |
contract = web3.eth.contract(address=contract_address, abi=contract_abi) | |
# Wallet information | |
wallet_address = 'your_wallet_address' | |
wallet_private_key = 'your_wallet_private_key' | |
# Function to mint an NFT | |
def mint_nft(recipient_address, token_uri): | |
nonce = web3.eth.getTransactionCount(wallet_address) | |
tx = contract.functions.mintNFT(recipient_address, token_uri).buildTransaction({ | |
'chainId': 1, # Mainnet | |
'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()}") | |
# Example of minting an NFT | |
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