2017-09-24 108 views
0

我使用以太坊智能合约创建了一个DApp,用Solidity编写。从外部调用以太坊智能合约功能的最常见方式是什么?

我想与合约交互并向P2P游戏的获胜者支付代币。为了简单起见,游戏可能是摇滚纸剪刀。证人会主持这场比赛,并向合同发送一个电话支付给获胜者。

说我们有两名球员:player 1有一个复仇​​的钱包与公钥a1b2c3d4e5(该轮的胜者)

player 2f6g7h8i9j0公钥(该轮的失败者)

会如何证人在我的Solidity智能合约中访问该函数,该合同将从游戏端支付player 1

+0

结帐此示例代码https://github.com/truffle-box/pet-shop-box –

+0

你能分享你的智能合约和app.js –

回答

0

您可以使用embark framework构建与etherium区块链交互的分散式HTML5应用程序。

Embark包含一个快速运行的测试库&在EVM(以太坊虚拟机)中测试您的合同。

登船支持IPFS。

您可以创建智能的合同,如:

pragma solidity ^0.4.7; 
contract SimpleStorage { 
    uint public storedData; 

    function SimpleStorage(uint initialValue) { 
    storedData = initialValue; 
    } 

    function set(uint x) { 
    storedData = x; 
    } 
    function get() constant returns (uint retVal) { 
    return storedData; 
    } 
} 

事件可以从JS框架触发这样

myContract.eventName({from: web3.eth.accounts}, 'latest') 
    .then(function(event) { console.log(event) }); 

在IPFS连接的通信是这样

//set yourself as the ipfs provider 

EmbarkJS.Messages.setProvider('orbit', {server: 'localhost', port: 5001}) 

EmbarkJS.Messages.sendMessage({topic: "sometopic", data: 'hello world'}) 
相关问题