1

Its a bit of a long question... I am using Go to deploy a Smart Contract using the following code:

client, err := ethclient.Dial("http://localhost:8545")
if err != nil {
    errorhandler.HandleErr(err, 1)
}

privateKey, err := crypto.HexToECDSA(hexKey)

if err != nil {
    errorhandler.HandleErr(err, 2)
}

publicKey := privateKey.Public()

publicKeyEcdsa, ok := publicKey.(*ecdsa.PublicKey)

if !ok {
    errorhandler.HandleErr(errors.New("pub key not of type ecdsa.PublicKey"), 3)
}

fromAddr := crypto.PubkeyToAddress(*publicKeyEcdsa)
nonce, err := client.PendingNonceAt(context.Background(), fromAddr)

if err != nil {
    errorhandler.HandleErr(err, 4)
}

gasPrice, err := client.SuggestGasPrice(context.Background())

if err != nil {
    errorhandler.HandleErr(err, 5)
}

auth := bind.NewKeyedTransactor(privateKey)
auth.Nonce = big.NewInt(int64(nonce))
auth.GasLimit = uint64(4700000)
auth.GasPrice = gasPrice

address, tx, instance, err := eddns.DeployEddns(auth, client)

if err != nil {
    errorhandler.HandleErr(err, 6)
}

_ = instance
return address.Hex(), tx.Hash(), auth

The above code completes successfully and I get a contract address (as a hex) and transaction hash.

I then use the hex address returned by the above function to load the contract like this:

client, err := ethclient.Dial(rawurl)

if err != nil {
    errorhandler.HandleErr(err, 7)
}
address := common.HexToAddress(hexAddr)
instance, err := eddns.NewEddns(address, client)

if err != nil {
    errorhandler.HandleErr(err, 8)
}

return instance

The above code complete successfully as well. No errors are thrown and I get the instance returned.

I then try to query my smart contract like this:

ip, err := contract.GetIp(nil, []byte(domain), tld, rType)

This is a function call and not a transaction so it should work. But I get an error thrown which is No contract code at give address

I am deploying to a private Ethereum network which I bring up using docker-compose up. The docker-compose.yml file is a bit long but I will show the Dockerfile of the node which I connect to at localhost:8545:

FROM ubuntu:xenial

RUN apt-get update \
     && apt-get install -y wget software-properties-common \
     && rm -rf /var/lib/apt/lists/*

WORKDIR "/root"

RUN add-apt-repository -y ppa:ethereum/ethereum

ARG binary
RUN apt-get update \
     && apt-get install -y ethereum

ARG password
ARG privatekey
RUN echo $password > ~/.accountpassword
RUN echo $privatekey > ~/.privatekey
ADD ./genesis.json ./genesis.json
RUN geth init genesis.json
RUN geth account import --password ~/.accountpassword  ~/.privatekey

ENV address=""
ENV bootnodeId=""
ENV bootnodeIp=""

CMD exec geth --bootnodes "enode://$bootnodeId@$bootnodeIp:30301" --networkid "500" --verbosity=4 --rpc --rpcaddr "0.0.0.0" --rpcapi "eth,web3,net,admin,debug,db,personal" --rpccorsdomain "*" --syncmode="full"

EXPOSE 8545
EXPOSE 30303

If the entire docker-compose.yml file is needed I can provide it.

This works perfectly when using the Ganache test network. No errors are thrown and I can successfully query the smart contract. Its when I try to interact with the private Ethereum network, I run into problems.

Thanks.

  • in the line with contract.GetIp() where is contract being set? – Miguel Mota Mar 25 at 21:18
  • @MiguelMota Hi. Yeah that part of the code is a bit long which is why I did not link it. But you can see it in this blob: github.com/sahirug/ethereum-dns-server/blob/… Basically its passed in as a function parameter – user3536523 Mar 25 at 21:21
  • Haven't ran your code but your code looks right – Miguel Mota Mar 25 at 21:57
  • @MiguelMota I think so too, because it works perfectly in Ganache. Its just when Im trying to deploy it on my private Ethereum network on Docker, the problems arise. Which is why I think, its an issue with my Dockerfile or docker-compose – user3536523 Mar 25 at 22:18

Your Answer

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

Browse other questions tagged or ask your own question.