英文:
How can I connect to already deployed smart contracts with Go?
问题
我是一名初出茅庐的区块链开发者,我一直在使用Go语言来深入学习,因为这是我最熟悉的语言。
现在我遇到了一个难题,希望能得到一些帮助。
我看过的几乎所有关于使用Go处理智能合约的教程都涉及使用geth将Solidity源代码编译为ABI和二进制形式,然后生成一个带有与合约进行部署和其他操作的绑定的.go文件。
当我处理自己创建的合约时,这种方法很好用,但是如果我要与已部署的第三方合约进行交互,比如Cryptokitties,我该怎么办呢?基本上,在我可能无法访问合约源代码以生成绑定的情况下,该怎么办呢?
在学习Cryptozombies课程时,使用Solidity时,我只需要定义所需合约的接口,但是Go似乎没有那么直接。
英文:
I'm a budding blockchain dev, and I've been using Go to dive into things as that's the language I'm most comfortable with.
I've at an impasse now, and hope I can get some help.
Pretty much all the tutorials I've seen on working with smart contracts with Go involve using geth to compile the Solidity source code to its ABI and binary forms then generating a .go file with bindings to the contract for deployment and other actions.
This is fine when working with my own created contracts, but how would I go around interfacing with already deployed third-party contracts such as Cryptokitties for instance? Basically, in the cases where I may not have the luxury of having access to the contract source code to generate bindings.
Going through the Cryptozombies course, with Solidity I just had to define the interfaces of the desired contract, but Go doesn't seem to be as straightforward.
答案1
得分: 1
你可以手动将ABI文件从Etherscan保存到本地工作空间以生成绑定。
例如,你可以从这个CryptoKitties合约中复制ABI。只要合约已经验证,你就可以随时获取ABI。
注意:
- Solidity是唯一不需要ABI的语言,因为它是在EVM(以太坊虚拟机)上进行合约开发的本地语言。
- 你也可以使用Etherscan API来以编程方式检索ABI。但在大多数情况下,我认为我们不需要走得那么远。
阅读更多:https://geth.ethereum.org/docs/dapp/native-bindings
英文:
You could manually save the ABI files from Etherscan to your local workspace to generate the binding.
For example, you can copy ABI from this CryptoKitties contract. As long as the contracts are verified, you can always get the ABIs.
Note:
- Solidity is the only language that doesn't need ABI because it is the native language of the contract development on the EVM (Ethereum Virtual Machine).
- You could also use Etherscan API to programmatically retrieve the ABI. But I don't think we need to go that far in most of the cases.
Read more: https://geth.ethereum.org/docs/dapp/native-bindings
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论