作者ousapas (komica123)
看板DigiCurrency
标题Re: [闲聊] web3怎麽使用合约
时间Wed Aug 8 18:56:50 2018
※ 引述《Tim20502 (恩)》之铭言:
: 最近在连接testrpc可以使用合约,但在转换到metamask使用的时候就发现这个问题…
: https://i.imgur.com/bBu9kVR.jpg
Metamask不支援sync function call
一定要用callback的方式取值
范例 (需Metamask ropsten)
https://output.jsbin.com/yihegurowu
Contract
pragma solidity ^0.4.24;
contract PTT {
function hello () public pure returns (string) {
return 'Hello PTT';
}
}
Contract Address
0x100e3d1600788d4606107120fdf30ec6657e412a
JS
const ABI = [
{
"constant": true,
"inputs": [],
"name": "hello",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "pure",
"type": "function"
}
];
const PttContract = web3.eth.contract(ABI);
const ptt = PttContract.at("0x100e3d1600788d4606107120fdf30ec6657e412a");
ptt.hello((err,result) => document.getElementById("output").innerHTML =
result);
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.227.169.72
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/DigiCurrency/M.1533725813.A.A59.html
※ 编辑: ousapas (36.227.169.72), 08/08/2018 19:30:04
1F:→ Tim20502: 谢谢 08/08 23:18
2F:推 Tim20502: 这是我改的,但还是没反应… 08/09 14:14