-
Notifications
You must be signed in to change notification settings - Fork 0
/
mint.py
83 lines (68 loc) · 2.26 KB
/
mint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from pycardano import *
import json
NETWORK = Network.TESTNET
chain_context = BlockFrostChainContext(
project_id='',
network=NETWORK
)
# Token minter
skey1 = PaymentSigningKey.load("usr1.skey")
vkey1 = PaymentVerificationKey.from_signing_key(skey1)
addr1 = Address(vkey1.hash(), network=NETWORK)
policy_skey = PaymentSigningKey.load("policy.skey")
policy_vkey = PaymentVerificationKey.from_signing_key(policy_skey)
# Receiver of token
skey2 = PaymentSigningKey.load("usr2.skey")
vkey2 = PaymentVerificationKey.from_signing_key(skey2)
addr2 = Address(vkey2.hash(), network=NETWORK)
#---- Create policy id (hash of policy script) ----
pubkey_policy = ScriptPubkey(policy_vkey.hash())
must_before_slot = InvalidHereAfter(70_000_000)
policy = ScriptAll([pubkey_policy, must_before_slot])
policy_id = policy.hash()
print(f"policy_id: {policy_id}", end='\n\n')
with open("./policy.id", "w") as f:
f.write(policy_id.payload.hex())
#---- Create token ----
token = MultiAsset.from_primitive(
{
policy_id.payload: {
b'FingerLickinGood6969': 1
}
}
)
#---- Create metadata ----
metadata = {
721: {
policy_id.payload.hex(): {
'FingerLickinGood6969': {
'description': "Finger Licking Good Token",
'name': 'FingerLickingGood6969',
'id': 6969,
'image': 'ipfs://QmRhTTbUrPYEw3mJGGhQqQST9k86v1DPBiTTWJGKDJsVFw'
}
}
}
}
with open('./metadata.txt', "w") as f:
json.dump(metadata, f)
#---- Build and submit minting tx ----
builder = TransactionBuilder(chain_context)
auxiliary_data = AuxiliaryData(AlonzoMetadata(metadata=Metadata(metadata)))
builder.auxiliary_data = auxiliary_data
builder.ttl = must_before_slot.after
builder.native_scripts = [policy]
builder.mint = token
builder.add_input_address(addr1)
# min_val = min_lovelace(Value(0, token), chain_context) # or just 2_000_000 flat
builder.add_output(
TransactionOutput(
addr2,
Value(2_000_000, token)
)
)
signed_tx = builder.build_and_sign(signing_keys=[skey1, policy_skey], change_address=addr1)
print(signed_tx, end="\n\n")
print(f"transaction id: {signed_tx.id}", end='\n\n')
chain_context.submit_tx(signed_tx.to_cbor())
print("######## Transaction submitted #########")