Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use Solidity with NodeJS?

I want to develop a blockchain system with smart contract using NodeJs for blockchain and Solidity for smart contract, i Google'd this but i found no answer ?

actually, i developped a blockchain system using javascript and new langage for smart contract, but this langage doesn't contain a lot of instruction so using solidity will be very useful, i wonder if possible to user solidity on blockchain chains which are developped by javascript ?

And if there is any post contains a description of how using that. Thanks you in advance.

like image 928
JSecurity Avatar asked Oct 15 '25 23:10

JSecurity


1 Answers

Yes you can, you use truffle to compile to contract to JSON file and then import it to your Javascript code and use it.

https://www.trufflesuite.com/docs/truffle/getting-started/compiling-contracts

  • First, you truffle compile to generate your json file
  • Import the json file to your code
  • const your_contract = web3.eth.contract(contract.json.abi)
  • const contract = your_contract.at(<your_contract_address)

And then after that, you can use your contract's methods. contract.<your_function>

like image 71
Quang Võ Avatar answered Oct 17 '25 11:10

Quang Võ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!