12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- from django.shortcuts import render
- from django.http import HttpResponse
- import json
- from pathlib import Path
- from erdpy import utils
- from django.views.decorators.csrf import csrf_protect, csrf_exempt
- from erdpy import cli_shared, testnet
- from erdpy.accounts import Account, Address
- from erdpy.contracts import CodeMetadata, SmartContract
- from erdpy.proxy.core import ElrondProxy
- # Create your views here.
- def index(request):
- return render(request, 'index.html')
- @csrf_exempt # disable this on deploy
- def deploy_contract_function(request):
- ##Arguments
- #--proxy
- #--pem
- proxy="https://testnet-gateway.elrond.com"
- pem_user="/home/ubuntu-test/Desktop/proj2/backend_dev/Market_Place_NFT/backend/wallet/users/sergiu.pem"
- response_data="asdas"
-
- proxy = ElrondProxy(proxy)
- network = proxy.get_network_config()
- user = Account(pem_file=pem_user)
- user.sync_nonce(proxy)
- bytecode_path = Path("/home/ubuntu-test/Desktop/proj2/project3/my_contract/output/my_contract.wasm").absolute()
- bytecode = utils.read_binary_file(bytecode_path).hex()
- code_metadata = CodeMetadata(upgradeable=True)
- contract = SmartContract(bytecode=bytecode, metadata=code_metadata)
- tx = contract.deploy(
- owner=user,
- arguments=[],
- gas_price=network.min_gas_price,
- gas_limit=60000000,
- value=0,
- chain=network.chain_id,
- version=network.min_tx_version
- )
- tx_on_network = tx.send_wait_result(proxy, 5000)
- write_logs_to_file(f"Contract address: {contract.address.bech32()}")
- write_logs_to_file(f"Deployment transaction: {tx_on_network.get_hash()}")
- return HttpResponse(
- json.dumps(f"Contract address: {contract.address.bech32()}"+f"Deployment transaction: {tx_on_network.get_hash()}"),
- content_type="application/json"
- )
- def write_logs_to_file(log_details):
- f = open("logfile.txt", "a")
- f.write(log_details)
- f.close()
|