PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 28, 2022

[FIXED] How to add smart contract functionality in PHP?

 July 28, 2022     blockchain, ethereum, php, solidity, web3js     No comments   

Issue

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.


Solution

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.



Answered By - Zulhilmi Zainudin
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing