Home > Blockchain >  How can I connect to already deployed smart contracts with Go?
How can I connect to already deployed smart contracts with Go?

Time:06-16

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.

CodePudding user response:

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

  • Related