1

Imagine this scenario, I have a contract that has a function where I call with runtime.Call().

But this function returns an address of a newly created contract, but not the bytecode as runtime.Create does.

How would I access that bytecode?

Thanks!!

  • 1
    eth_getcode is invokable over RPC or IPC. – Raghav Sood Aug 6 '18 at 16:14
  • Yeah, but I am woking directly to the evm creating a genesis file. So I need to get all that data included in a genesis. So I dont have access from outside of the blockchain, because it is not even instantiate. But this gives me a good idea, I can review how that eth_getcode is implemented in the lowlevel. Thanks! – Jonathan Gimeno Aug 6 '18 at 16:16
  • You can use geth to init a chain with your genesis, and then geth dump 0 to dump the genesis block state trie, which will contain the code and balances for every account – Raghav Sood Aug 6 '18 at 16:27
  • what bytecode ??? the bytecode of the contract? it is part of the transaction, a field called extra data, also called input when evm.Call() is executed. – Nulik Aug 6 '18 at 18:00
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.