Link Javascript to Solidity?

688 views Asked by At

Is it possible to link/connect/ send a signal from JavaScript code into Solidity/Ethereum?

3

There are 3 answers

2
Dane Pilcher On

You can use web3.

There is a different syntax for interfacing with contracts. Depending on if the contract is already deployed or you need to do that yourself.

When you have the contract instance you can then call contract methods.

const ChessGame = web3.eth.contract(abiArray);
const contractInstance = ChessGame.at(address);
contractInstance.declareWinner(winner, function (err, res) {
  // do something
});

I personally think web3 is a little cumbersome. I recommend checking out Truffle and following some of their tutorials to get up to speed.

0
vigilance On

You could install the official Go implementation of the Ethereum protocol, geth.

Geth is a tool for running a local node/miner and also allows you to connect to a running blockchain via the console (which then becomes a Javascript console) and input RPC calls natively via the provided web3 package.

Geth also supports connecting to test nets (such as Ropsten or Rinkeby) or even a private blockchain on localhost.

Additionally to a user interacting directly with the console via the command line, geth can be configured from a shell script/batch file to both run or preload javascript files containing scripted commands for testing!

0
John Bradshaw On

yes just create an ABI of your smart contract and then interact with your smart contracts however you see fit via web3.