1

I have a piece of code that connects to the network and displays transaction data.

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    conn, err := ethclient.Dial("https://mainnet.infura.io")
    if err != nil {
        log.Fatal("Whoops something went wrong!", err)
    }

    ctx := context.Background()
    tx, pending, _ := conn.TransactionByHash(ctx, common.HexToHash("0x30999361906753dbf60f39b32d3c8fadeb07d2c0f1188a32ba1849daac0385a8"))
    if !pending {
        fmt.Println(tx)
    }

}

I would like to get a code from a contract account , how can i get it by modifying this code, with only the address of this account.

I try do it

conn.CodeAt(address)

but the CodeAt method needs more parameters.

2

From https://godoc.org/github.com/obscuren/go-ethereum/ethclient#Client.CodeAt:

func (ec *Client) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)

CodeAt returns the contract code of the given account. The block number can be nil, in which case the code is taken from the latest known block.

So, e.g.:

conn.CodeAt(context.Background(), address, nil);

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.