universal-wallet-contract/signer/deploy_collection.py

65 lines
4.5 KiB
Python

from base64 import b64encode
from tonsdk.contract.token.nft import NFTCollection, NFTItem
from tonsdk.contract.wallet import Wallets
import os
import asyncio
from tonsdk.utils import Address
import httpx
import time
WALLET_MNEMONIC = os.getenv('WALLET_MNEMONIC', 'lucky odor welcome cool climb cream sauce either piece embark ritual purpose bacon timber please nest paddle obscure student wheel police speak acquire cream').split(' ')
WALLET_VERSION = os.getenv('WALLET_VERSION', 'v3r2')
async def main():
_, _, _, wallet = Wallets.from_mnemonics(WALLET_MNEMONIC, WALLET_VERSION)
print(f"Wallet address: {wallet.address.to_string(1, 1, 1)}")
collection = NFTCollection(
code='b5ee9c724102160100029f000114ff00f4a413f4bcf2c80b01020162020f0202cd030a04e9d10638048adf000e8698180b8d848adf07d201800e98fe99ff6a2687d20699fea6a6a184108349e9ca829405d47141baf8280e8410854658056b84008646582a802e78b127d010a65b509e58fe59f80e78b64c0207d80701b28b9e382f970c892e000f18112e001718112e001f18112c1006599dd40405060700603502d33f5313bbf2e1925313ba01fa00d43028103459f0068e1201a44343c85005cf1613cb3fccccccc9ed54925f05e200a6357003d4308e378040f4966fa5208e2906a4208100fabe93f2c18fde81019321a05325bbf2f402fa00d43022544b30f00623ba9302a402de04926c21e2b3e6303250444313c85005cf1613cb3fccccccc9ed54002c323401fa40304144c85005cf1613cb3fccccccc9ed5402fe8e6d35028040d721d401d0237020718e14037aa90ca63024a812a003aa0702a421c0004430e6306c1282182e6a736f6e82606e6674732f6d657461646174612fc8cb6f03aa0213cf01cb27c9c8cc01cf1601fa003001c923544730f00601a44343c85005cf1613cb3fccccccc9ed54e010345f04328200cb38bae30230840f0809002cf404f40430216e91319301fb04e2206e913092ed54e20004f2f00201200b0e0201200c0d002d007232cffe0a33c5b25c083232c044fd003d0032c03260001b3e401d3232c084b281f2fff27420003d45af0047021f005778018c8cb0558cf165004fa0213cb6b12ccccc971fb008020120101502012011120043b8b5d31ed44d0fa40d33fd4d4d43010245f04d0d431d430d071c8cb0701cf16ccc980201201314002fb5dafda89a1f481a67fa9a9a860d883a1a61fa61ff480610002db4f47da89a1f481a67fa9a9a86028be09e008e003e00b00025bc82df6a2687d20699fea6a6a182de86a182c4699353e6',
owner_address=Address('EQC6VQVXeuRdLqFmbAdeJywe2pO7eyasZTWqVdHKo-vdgsBE'),
collection_content_uri='https://geton.farm/nfts/collection/meta.json',
nft_item_content_base_uri='https://geton.farm/nfts/collection/',
nft_item_code_hex='b5ee9c7241020e01000229000114ff00f4a413f4bcf2c80b01020162020d0202ce030a020120040903b90c8871c02497c0f83434c0c05c6c2497c0f83e903e900c7e800c5c75c87e800c7e800c1cea6d003c00812cf8c081b4c7f4cfe08417f30f45148c2ea3a24c840dd78c9004f6cf380c0d0d0d4d60840bf2c9a884aeb8c097c12103fcbc2005060800ca306c22345232c705f2e19501fa40d45423405235f00321c701c0008e4401fa00218e3a821005138d9170c85006cf1658cf161034413073708010c8cb055007cf165005fa0215cb6a12cb1fcb3f226eb39458cf17019132e201c901fb00925f04e2925f03e201f65135c705f2e191fa4021f001fa40d20031fa00820afaf0801ba121945315a0a1de22d70b01c300209206a19136e220c2fff2e192218e3e821005138d91c85009cf16500bcf16712449145446a0708010c8cb055007cf165005fa0215cb6a12cb1fcb3f226eb39458cf17019132e201c901fb00104794102a375be2070082028e3526f0018210d53276db103744006d71708010c8cb055007cf165005fa0215cb6a12cb1fcb3f226eb39458cf17019132e201c901fb0093303234e25502f00300727082108b77173505c8cbff5004cf1610248040708010c8cb055007cf165005fa0215cb6a12cb1fcb3f226eb39458cf17019132e201c901fb0000113e910c1c2ebcb853600201200b0c003b3b513434cffe900835d27080269fc07e90350c04090408f80c1c165b5b60001d00f232cfd633c58073c5b3327b55200009a11f9fe005df38d804',
royalty=0.2,
royalty_address=Address('UQDLahdbuqdPW7YoFP5_HxIcVrraziR6IBmeEYgruHCntCrb'),
)
print(f"Collection address: {collection.address.to_string(1, 1, 1)}")
wallet_seqno = httpx.get(f'https://tonapi.io/v2/blockchain/accounts/{wallet.address.to_string(1, 1, 1)}/methods/seqno').json()
print("Wallet seqno response:", wallet_seqno)
try:
assert not ('error' in wallet_seqno)
assert wallet_seqno['exit_code'] == 0
wallet_seqno = int(wallet_seqno['stack'][0]['num'], 16)
except:
wallet_seqno = 0
print(f"Wallet seqno: {wallet_seqno}")
# time.sleep(4)
query = wallet.create_transfer_message(
collection.address.to_string(0, 1, 1),
2e7,
wallet_seqno,
state_init=collection.create_state_init()['state_init']
)
print(
httpx.post(
'https://toncenter.com/api/v2/sendBoc',
json={
'boc': b64encode(query['message'].to_boc(False)).decode()
}
).json()
)
if __name__ == '__main__':
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.close()