简体   繁体   English

将 Javascript 链接到 Solidity?

[英]Link Javascript to Solidity?

是否可以将 JavaScript 代码中的信号链接/连接/发送到 Solidity/Ethereum?

You can use web3 .您可以使用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.我个人认为web3有点麻烦。 I recommend checking out Truffle and following some of their tutorials to get up to speed.我建议查看Truffle并遵循他们的一些教程以加快速度。

You could install the official Go implementation of the Ethereum protocol, geth .您可以安装以太坊协议的官方 Go 实现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 是一种用于运行本地节点/矿工的工具,还允许您通过控制台(然后变成 Javascript 控制台)连接到正在运行的区块链,并通过提供的 web3 包本地输入 RPC 调用。

Geth also supports connecting to test nets (such as Ropsten or Rinkeby) or even a private blockchain on localhost. Geth 还支持连接到测试网络(例如 Ropsten 或 Rinkeby)甚至本地主机上的私有区块链。

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!除了通过命令行直接与控制台交互的用户之外,还可以从 shell 脚本/批处理文件配置 geth 以运行或预加载包含脚本命令的 javascript 文件以进行测试!

是的,只需创建您的智能合约的 ABI,然后与您的智能合约进行交互,但您认为可以通过 web3 进行交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM