Yes it is! Use the client CodeAt
method of the ethclient
package to read the bytecode of a deployed smart contract. Here's a full example:
package main
import (
"context"
"encoding/hex"
"fmt"
"log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
func main() {
client, err := ethclient.Dial("https://rinkeby.infura.io")
if err != nil {
log.Fatal(err)
}
contractAddress := common.HexToAddress("0x147B8eb97fD247D06C4006D269c90C1908Fb5D54")
bytecode, err := client.CodeAt(context.Background(), contractAddress, nil) // nil is latest block
if err != nil {
log.Fatal(err)
}
fmt.Println(hex.EncodeToString(bytecode)) // 60806...10029
}
It'll be the same result as seen on etherscan
geth dump 0
to dump the genesis block state trie, which will contain the code and balances for every accountextra data
, also calledinput
when evm.Call() is executed.