Last active
December 27, 2021 10:33
-
-
Save Dimfred/2ca6835fd54562f9853440a51887e6e5 to your computer and use it in GitHub Desktop.
This file contains 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
# pip3 install pysha3 eth-account requests | |
from eth_account.messages import encode_defunct | |
from eth_account import Account | |
import sha3 | |
import json | |
import os | |
import requests as req | |
acc = Account.from_key("4c4b2554e43b374f4cafdd5adaeea5e9aff9b3be54d329bc939752bb747294b9") | |
payload = { | |
"contract_address": "0xb72d1aa092cf5b3b50dabb55bdab0f33dfab37b7", | |
"royalties": [ | |
{"recipient": "0xea047d1919b732a4b9b12337a60876536f4f2659", "percentage": 4} | |
], | |
"users": [ | |
{ | |
"user": "0xea047d1919b732a4b9b12337a60876536f4f2659", | |
"tokens": [ | |
{ | |
"id": "2", | |
"blueprint": "x", | |
"royalties": [ | |
{ | |
"recipient": "0xea047d1919b732a4b9b12337a60876536f4f2659", | |
"percentage": 3.5, | |
} | |
], | |
} | |
], | |
} | |
], | |
"auth_signature": "", | |
} | |
str_payload = json.dumps(payload, separators=(",", ":")) | |
hash_gen = sha3.keccak_256() | |
hash_gen.update(str.encode(str_payload)) | |
message = "0x" + hash_gen.hexdigest() | |
signature = acc.sign_message(encode_defunct(text=message)) | |
str_siggy = signature.signature.hex() | |
def parseEnd(siggy): | |
siggy_end = siggy[len(siggy) - 2 :] | |
num = int(siggy_end, 16) | |
if num == 27: | |
return str(num).rjust(2, "0") | |
else: | |
return str(num - 27).rjust(2, "0") | |
auth_signature = str_siggy[:-2] + parseEnd(str_siggy) | |
payload["auth_signature"] = auth_signature | |
res = req.post( | |
"https://api.ropsten.x.immutable.com/v2/mints", json=[payload] | |
) | |
print(res.text) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment