简体   繁体   English

如何从不同节点访问合约功能?

[英]How can i access the function of contract from different nodes?

I am having two contracts say A and B, and two nodes running in different machines Machine1 and Machine 2 with same network id and i had added the peer using node url. 我有两个合同,分别是A和B,两个节点在具有相同网络ID的不同机器Machine1和Machine 2中运行,并且我已使用节点url添加了对等方。 Contract A is deployed by machine1 on blockchain, Contract B is deployed by machine2.Now i want access the function of contract A from machine2 and machine 1 and also access the function of contract B from machine2 and machine 1.How can i access the functions 合约A由机器1部署在区块链上,合约B由机器2部署。现在我要从机器2和机器1访问合约A的功能,还想从机器2和机器1访问合约B的功能

The Ethereum blockchain is a distributed application platform. 以太坊区块链是一个分布式应用平台。 This means that contract code is not deployed to a specific node; 这意味着合同代码未部署到特定节点。 rather, it is deployed to a distributed ledger of which each node has a copy (assuming that each node has reached consensus with the rest of the network). 而是将其部署到每个节点都有副本的分布式分类帐(假设每个节点已与网络的其余部分达成共识)。 Likewise, when you call a function of a contract, the function call is executed at least on those nodes in your network that are actively mining (validating transactions). 同样,当您调用合同的功能时,该功能调用至少在网络中正在主动挖掘(验证交易)的那些节点上执行。

Contracts are created by broadcasting a transaction to the network. 通过向网络广播交易来创建合同。 Functions on deployed contracts are called also by broadcasting a transaction. 通过广播交易也可以调用已部署合同的功能。

Preparation of the transaction that creates a contract returns the address of the contract. 准备创建合同的交易将返回合同的地址。 This address references the unique location of the contract on the blockchain; 该地址引用了合约在区块链上的唯一位置; record it. 把它记录下来。 When you send that transaction to the blockchain, wait for the current block to be mined. 当您将该交易发送到区块链时,请等待当前区块被开采。 Once that happens, all nodes should have a copy of the code within a few milliseconds and can then process transactions that call functions in that contract. 一旦发生这种情况,所有节点都应在几毫秒内获得代码的副本,然后可以处理调用该合约中的函数的事务。

Once the contract is created, prepare another transaction that calls a function, referencing as the recipient of the transaction the contract address that you previously recorded. 创建合同后,准备另一个调用函数的事务,将您先前记录的合同地址作为事务的收件人。 Then, broadcast this transaction to the network. 然后,将此交易广播到网络。 It doesn't matter which node receives the transaction first. 哪个节点首先接收事务无关紧要。 Eventually, shortly after the transaction is mined, all nodes in the network will have an updated state of the blockchain that reflects any changes that resulted from the function call. 最终,在交易被开采后不久,网络中的所有节点将具有区块链的更新状态,该状态反映了由函数调用导致的任何更改。

To generate Abi goto https://etherchain.org/solc and place your contract code and get the abi 要生成Abi,请转到https://etherchain.org/solc并放置您的合同代码并获取abi

Use var contract = eth.contract(abi).at(contractaddress) 使用var contract = eth.contract(abi).at(contractaddress)

Replace abi and address with the ABI and address of the contract. 用合同的ABI和地址替换abi和地址。

This will allow you to access the contract. 这将使您可以访问合同。

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

相关问题 为什么我可以在一个 function 而不是另一个中访问我的合同 - Why I can access my contract in one function but not another one 如何在不同的 function 中访问我的 websocket? - How can I access my websocket inside of a different function? 当我从其他合约调用 ERC20 合约中的转账 function 时出错,但是,可以使用 mint/burn - Error when I call transfer function in ERC20 contract from other contract, But, can use mint/burn 如何从其他域上的iframe访问父DOM? - How can I access a parent DOM from an iframe on a different domain? 在 JavaScript 中,如何访问子节点的属性? - In JavaScript, How can I access properties of children nodes? 如何访问Sankey图表的节点属性 - How can I access nodes properties of a Sankey chart 如何查询不同节点的热门帖子? - How can I query the top posts of different nodes? 我怎样才能访问一个函数? - How can i access a function? 如何从全局范围访问函数中的变量? - How can I access variables in a function from the global scope? 如何从闭包中的函数内部访问闭包中的变量? - How can I access variables in a closure from inside of a function in that closure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM