[英]How can I run a python script through brownie from a typescript?
I am developing a solidity smart contract and I'm deploying it through a python code that I run through brownie with command lines.我正在开发一个可靠的智能合约,我正在通过一个 python 代码部署它,我使用命令行通过 brownie 运行该代码。 Also, I am developing a front-end dApp with typescript to interact and also to deploy those contracts.
此外,我正在开发一个带有 typescript 的前端 dApp 来交互并部署这些合约。 Using useDApp allows me to interact with already deployed contracts, but I still haven't figured out how to deploy those contracts through the front-end.
使用 useDApp 可以让我与已经部署的合约进行交互,但我仍然没有弄清楚如何通过前端部署这些合约。
To make it short, the "deploy.py" code has a function that deploys the solidity code and it passes to the contract some variables to the constructor.简而言之,“deploy.py”代码有一个 function 用于部署solidity 代码并将一些变量传递给合约的构造函数。 It works fine.
它工作正常。
On the front-end of the App (typescript) I have a form that users can fill out, and then when they click on the "send" button, those fields turn into variables.在应用程序(打字稿)的前端,我有一个用户可以填写的表单,然后当他们单击“发送”按钮时,这些字段会变成变量。 All I need now is to pass those variables to the "deploy.py" file so it can cast them to the solidity constructor, and, of course, deploy the contract through brownie.
我现在需要的只是将这些变量传递给“deploy.py”文件,这样它就可以将它们转换为solidity 构造函数,当然,还可以通过brownie 部署合约。
The only way to make the front end talk with python backend is to create a restful api with Flask.使前端与 python 后端对话的唯一方法是使用 Flask 创建一个宁静的 api。 So when you submit the form, you will send a post request to python server, python flask will extract the posted data with
request.json
因此,当您提交表单时,您将向 python 服务器发送一个 post 请求,python flask 将使用
request.json
提取已发布的数据。
from flask import Flask
from flask import request
app = Flask(__name__)
# allow only post request here
@app.route('/deploy_contract_route', methods = ['POST'])
def deploy_contract():
content_type = request.headers.get('Content-Type')
if (content_type == 'application/json'):
json = request.json
# json includes the post data. now you past this to deploy request. you get individual fields data
deploy_contract_script(pass_args_here):
# what ever deploying logic runs here
return value_to_front_end
else:
return 'Content-Type not supported!'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.