8

(不使用truffle console)如何以合约的方式调用truffle部署好的合约 | 登链社区 | 技...

 2 years ago
source link: https://learnblockchain.cn/question/3091
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

(不使用truffle console)如何以合约的方式调用truffle部署好的合约

55 (不使用truffle console)如何以合约的方式调用truffle部署好的合约

Hi,各位大佬好,我刚开始接触智能合约。
目前已经可以使用Remix Desktop IDE中编写服务端.sol,同时编写一个客户端.sol调用服务端.sol的接口。其实就是能把合约跑起来了。

但去看github上开源的很多合约时,发现他们都是使用truffle,研究了一下官方的doc,部署完成后是在truffle console中输入代码来调用服务端.sol函数的。文档和google都没提到如何按Remix IDE相同的办法调用服务端.sol

这样可能不太适合调试,我还是想编写一个客户端.sol来直接调用truffle部署好的服务端.sol,这样方便测试,可视化也好很多。

我试过本地安装ganache,然后配置truffle-config.js,让它部署到ganache上,再用Remix IDE客户端.sol,但选择Remix IDE的Web3 provider连接时没反应。

请问需要怎么做呢?非常感谢。不一定要用Remix客户端.sol,只要是直接用合约调用合约的方式都可以(而不是用truffle console命令)

最佳答案 1天前

在 console 里调用合约, 是从外部调用合约。

使用合约调用合约,可以查看这个答案:

https://learnblockchain.cn/question/2748

主要方式是通过接口定义一个类型,把合约地址转为接口类型,就可以调用了。

Tiny熊 - 布道者
擅长:智能合约,以太坊 | 采纳率 40% | 回答于 1天前
您需要登录后才可以回答问题,登录 或者 注册

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK