user8529348
user8529348

Reputation:

Link Javascript to Solidity?

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

Upvotes: 3

Views: 671

Answers (3)

John Bradshaw
John Bradshaw

Reputation: 189

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

Upvotes: 0

vigilance
vigilance

Reputation: 116

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!

Upvotes: 0

Dane Pilcher
Dane Pilcher

Reputation: 41

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.

Upvotes: 2

Related Questions