dsajkdadsa14222 2018-11-18 09:55
浏览 237
已采纳

如何在PHP中添加智能合约功能? [关闭]

I'm working on project with main theme - sales. So, for front end (React) and Backend(PHP).

I had a problem understanding how to use my smart contract in the project. For deploy i use ethereum wallet 0.9.0 and test network Rinkeby. In EW he is working.

Let's pretend that I have button buy in my code, and, i have function in my contract like:

function Buy() 
    public 
    payable 
{
    require (msg.sender != seller);
    require (msg.value >= price);
    orderNum++;
    safePay +=msg.value;
}

Now, how i can use it? I heard about web3.js, but (i'm not sure) i need php requests for this.

Or, if my contract deploy in ethereum-wallet Rinkeby i can use it straight from just code and don't need deploy again.

I'm beginner in this theme and can do mistake (even in the view), but will be very glad, if someone can explain this.

Thanks.

  • 写回答

1条回答 默认 最新

  • doutun1875 2018-11-18 10:40
    关注

    AFAIK, there is no official support for PHP yet. You have 2 options here to interact with Ethereum blockchain:

    1. Use JSON RPC - using curl or any HTTP client library written in PHP, you can communicate with the Ethereum blockchain. Calling data is easy. You might face some difficulties when you want to write/edit data in Ethereum blockchain because you need to deal with transaction signing and packing the data/payload.

    2. Use Web3JS - This is much easier and you'll find many resources online. The keyword that you can use is building dapp. Truffle and this YouTube channel are two good places to learn about building dapps using Web3JS.

    If you found this answer is helpful, please accept this answer and upvote. Good luck!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办