2 Commits f94d227ad6 ... 0968b122f0

Author SHA1 Message Date
  Sergiu 0968b122f0 Deploy smart contract using pure python library ERDPY using pem files and wasm file. 2 years ago
  Sergiu 4dc0fbe04d Deploy smart contract using pure python library ERDPY using pem files and wasm file. 2 years ago

+ 2 - 0
README.md

@@ -1,5 +1,6 @@
 # Market_Place_NFT
 
+# USE localhost:8000/index
 
 #ErdJS API for connection trought wallet \n
 #Backend NFT transaction - python
@@ -22,3 +23,4 @@ pip3 install django
 python3 manage.py migrate
 
 
+pip3 install erdpy

+ 38 - 1
backend/HomeApp/templates/index.html

@@ -1,9 +1,46 @@
 <html>
 <head>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
+
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
+
+    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
+
+    
 
 </head>
 <body>
     <h6>Home App</h6>
+    
+    <input type="button" onclick="deploy_contract()" value="Deploy contract"/> </br> </br>
+    <input type="button" onclick="connect_to_wallet()" value="Connect to wallet"/>
 </body>
 
-</html>
+</html>
+<script>
+
+
+
+function deploy_contract()
+{
+    alert("ceva");
+    
+    $.ajax({
+
+        type: 'POST',
+        url: "HomeApp/deploy_contract_function/",
+        data: "test",
+        dataType: 'text',
+        success: function (data) {
+            alert(data);
+        },
+        error: function (response) {
+            alert("Error");
+        }
+
+    })
+}
+
+</script>
+
+

+ 2 - 1
backend/HomeApp/urls.py

@@ -3,5 +3,6 @@ from django.urls import re_path as url
 from . import views
 
 urlpatterns = [
-    url('', views.index, name='index'),
+    url('index', views.index, name='index'),
+    url('deploy_contract_function', views.deploy_contract_function, name='deploy_contract_function')
 ]

+ 58 - 1
backend/HomeApp/views.py

@@ -1,6 +1,63 @@
 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')
+    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()

+ 1 - 1
backend/backend/settings.py

@@ -45,7 +45,7 @@ MIDDLEWARE = [
     'django.middleware.security.SecurityMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
-    'django.middleware.csrf.CsrfViewMiddleware',
+    #'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',

+ 1 - 0
backend/logfile.txt

@@ -0,0 +1 @@
+Contract address: erd1qqqqqqqqqqqqqpgq4nz8mtkcsfcl04wjxxt7kngz9ss3t7usylwqaa9tzkDeployment transaction: d60eaf0c9d47e25e8abda44f229fd6ab6e0d730e924bb31de2a36e2c732aed5dContract address: erd1qqqqqqqqqqqqqpgqlc2fl8e7ksax0pqsskqz3j993vl8dr74ylwqs86mn3Deployment transaction: b47feb1a8e6c302a74e42dfd7f1c6917ba21add36ff245d3ca60d4d94558c032

+ 5 - 0
backend/wallet/users/alice.pem

@@ -0,0 +1,5 @@
+-----BEGIN PRIVATE KEY for erd1w8g5t8f8nmx4750vzequg5zparl8s9n6er2jsguqhrtvn355y4zsrc4m6m-----
+YWU4ZGJkNGI4ZDUxZmM2NzkwMTlhZjM3OWEyNDlkMGI3ODlmYzQ1MzRkNGFkNGZh
+OWM3YjcxZGI5ZGEwZDNlOTcxZDE0NTlkMjc5ZWNkNWY1MWVjMTY0MWM0NTA0MWU4
+ZmU3ODE2N2FjOGQ1MjgyMzgwYjhkNmM5YzY5NDI1NDU=
+-----END PRIVATE KEY for erd1w8g5t8f8nmx4750vzequg5zparl8s9n6er2jsguqhrtvn355y4zsrc4m6m-----

+ 5 - 0
backend/wallet/users/sergiu.pem

@@ -0,0 +1,5 @@
+-----BEGIN PRIVATE KEY for erd1sf83n4xgymj27vkxl03kka7h4f7h9uu6y4zev6xtuy954jmqylwqe5t4vy-----
+MDYxZGU5ZTJmMzAzODBkYmNiYzgwZWY5Mzg1ZmIwYmIxY2NjOGMxZTY1NTZlZjE5
+ZDJjYWZjZmExOWFlNzQ5NTgyNGYxOWQ0YzgyNmU0YWYzMmM2ZmJlMzZiNzdkN2Fh
+N2Q3MmYzOWEyNTQ1OTY2OGNiZTEwYjRhY2I2MDI3ZGM=
+-----END PRIVATE KEY for erd1sf83n4xgymj27vkxl03kka7h4f7h9uu6y4zev6xtuy954jmqylwqe5t4vy-----

File diff suppressed because it is too large
+ 3771 - 0
my_env/bin/bottle.py


+ 8 - 0
my_env/bin/erdpy

@@ -0,0 +1,8 @@
+#!/home/ubuntu-test/Desktop/proj2/backend_dev/Market_Place_NFT/my_env/bin/python3
+# -*- coding: utf-8 -*-
+import re
+import sys
+from erdpy.cli import main
+if __name__ == '__main__':
+    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
+    sys.exit(main())

+ 8 - 0
my_env/bin/ledgercomm-send

@@ -0,0 +1,8 @@
+#!/home/ubuntu-test/Desktop/proj2/backend_dev/Market_Place_NFT/my_env/bin/python3
+# -*- coding: utf-8 -*-
+import re
+import sys
+from ledgercomm.cli.send import main
+if __name__ == '__main__':
+    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
+    sys.exit(main())

+ 8 - 0
my_env/bin/normalizer

@@ -0,0 +1,8 @@
+#!/home/ubuntu-test/Desktop/proj2/backend_dev/Market_Place_NFT/my_env/bin/python3
+# -*- coding: utf-8 -*-
+import re
+import sys
+from charset_normalizer.cli.normalizer import cli_detect
+if __name__ == '__main__':
+    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
+    sys.exit(cli_detect())

+ 8 - 0
my_env/bin/pysemver

@@ -0,0 +1,8 @@
+#!/home/ubuntu-test/Desktop/proj2/backend_dev/Market_Place_NFT/my_env/bin/python3
+# -*- coding: utf-8 -*-
+import re
+import sys
+from semver import main
+if __name__ == '__main__':
+    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
+    sys.exit(main())