Skip to content

Instantly share code, notes, and snippets.

@developerfred
Created December 9, 2022 20:26
Show Gist options
  • Save developerfred/3e34515ab7e0822f26df5c1362d2e8a4 to your computer and use it in GitHub Desktop.
Save developerfred/3e34515ab7e0822f26df5c1362d2e8a4 to your computer and use it in GitHub Desktop.

install libs

$ pip install web3

add your metamask pk here

private_key = '<your metamask key'

change user_data

user_data = {
    "pseudo": "codingsh",
    "coverPictureURL": "https://pbs.twimg.com/profile_banners/1188074510668435463/1663526205/1500x500",
    "profilePictureURL": "https://pbs.twimg.com/profile_images/1328136561653903360/NZ7sqTRd_400x400.jpg"
}

save and run script

python mintQuestID.py
# Importar a biblioteca web3.py
from web3 import Web3
import json
from web3.middleware import geth_poa_middleware
private_key = '<your metamask key'
# Inicializar uma conexão com um nó Ethereum
alchemy_url = "https://polygon-mumbai.g.alchemy.com/v2/SHtTQk0rnio42nZtp03tx_X5paDkzhwu"
w3 = Web3(Web3.HTTPProvider(alchemy_url))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
# Print if web3 is successfully connected
print(w3.isConnected())
# Definir o endereço do contrato ggProfiles
ggProfiles_address = "0x57c0107010e3001E3bf959fE48F18F83Df4BBbBC"
ggProfiles_abi = '[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_ticker","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_operator","type":"address"}],"name":"AddOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"_name","type":"string"}],"name":"AddSupportedThirdParty","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_userAddress","type":"address"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_userAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"DecreaseReputation","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_userAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"IncreaseReputation","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_userAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"_thirdPartyId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_thirdPartyUserId","type":"uint256"}],"name":"LinkThirdPartyToProfile","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_userAddress","type":"address"},{"indexed":false,"internalType":"string","name":"_pseudo","type":"string"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_operator","type":"address"}],"name":"RemoveOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_userAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"_thirdPartyId","type":"uint256"}],"name":"UnlinkThirdPartyToProfile","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_userAddress","type":"address"},{"indexed":false,"internalType":"string","name":"_pseudo","type":"string"}],"name":"Update","type":"event"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"}],"name":"addOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_thirdPartyName","type":"string"}],"name":"addThirdParty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"decreaseReputation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"}],"name":"getProfileData","outputs":[{"components":[{"internalType":"string","name":"pseudo","type":"string"},{"internalType":"string","name":"profilePictureURL","type":"string"},{"internalType":"string","name":"coverPictureURL","type":"string"},{"internalType":"bool","name":"isRegistered","type":"bool"},{"internalType":"uint256","name":"gainedReputation","type":"uint256"},{"internalType":"uint256","name":"lostReputation","type":"uint256"},{"components":[{"internalType":"uint256","name":"thirdPartyId","type":"uint256"},{"internalType":"uint256","name":"userID","type":"uint256"}],"internalType":"struct ggProfiles.ThirdParty[]","name":"linkedThirdParties","type":"tuple[]"}],"internalType":"struct ggProfiles.ProfileData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRegisteredAddresses","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"}],"name":"getReputation","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getThirdParties","outputs":[{"internalType":"string[]","name":"","type":"string[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"}],"name":"hasProfileData","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"increaseReputation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_pseudo","type":"string"}],"name":"isAvailable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"}],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_profileAddress","type":"address"},{"internalType":"uint256","name":"_thirdPartyId","type":"uint256"},{"internalType":"uint256","name":"_thirdPartyUserID","type":"uint256"}],"name":"linkThirdPartyToProfile","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"string","name":"pseudo","type":"string"},{"internalType":"string","name":"profilePictureURL","type":"string"},{"internalType":"string","name":"coverPictureURL","type":"string"}],"internalType":"struct ggProfiles.UpdatableByUserData","name":"_userData","type":"tuple"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"operators","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"registeredAddresses","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"}],"name":"removeOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"ticker","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_profileAddress","type":"address"},{"internalType":"uint256","name":"_thirdPartyId","type":"uint256"}],"name":"unlinkThirdPartyFromProfile","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"string","name":"pseudo","type":"string"},{"internalType":"string","name":"profilePictureURL","type":"string"},{"internalType":"string","name":"coverPictureURL","type":"string"}],"internalType":"struct ggProfiles.UpdatableByUserData","name":"_userData","type":"tuple"}],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"}]'
# Carregar o contrato ggProfiles em um objeto
ggProfiles = w3.eth.contract(address=ggProfiles_address, abi=ggProfiles_abi)
# Definir os dados do usuário
user_data = {
"pseudo": "codingsh",
"coverPictureURL": "https://pbs.twimg.com/profile_banners/1188074510668435463/1663526205/1500x500",
"profilePictureURL": "https://pbs.twimg.com/profile_images/1328136561653903360/NZ7sqTRd_400x400.jpg"
}
# Obter a conta que será usada para chamar a função mint
account = w3.eth.account.privateKeyToAccount(private_key)
# Chamar a função mint do contrato ggProfiles
txn = ggProfiles.functions.mint(user_data).buildTransaction(
{
"from": account.address,
"nonce": w3.eth.getTransactionCount(account.address)
}
)
signed_txn = w3.eth.account.sign_transaction(txn, private_key)
tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
# Esperar até que a transação seja confirmada
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(receipt.status)
# Verificar se o perfil foi criado com sucesso
# profile = ggProfiles.functions.profiles(account).call()
print("Profile created:")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment