1

I created a private network of POA, and I use clef to seal blocks like this: enter image description here

I have successfully run this chain becaues it can produce blocks and I can create transactions between 2 accounts, and transactions can be packed into the block successfully too. But when i want to create a smart contract on my private chain, my code is :

func main() {
    client, err := ethclient.Dial("./node1/geth.ipc")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(client, "successfully connected")

    file := "node1/keystore/UTC--2023-08-14T08-01-07.428821000Z--ec9607877c2df4c62a7bac8123bac9eac82f7115"

    jsonBytes, err := os.ReadFile(file)

    password, _ := os.ReadFile("./node1/password.txt")

    if err != nil {
        log.Fatal(err)
    }

    chainID, _ := client.ChainID(context.Background())
    Key, _ := keystore.DecryptKey(jsonBytes, string(password))
    fmt.Println(Key)

    auth, err := bind.NewTransactorWithChainID(strings.NewReader(string(jsonBytes)), string(password), chainID)
    if err != nil {
        log.Fatal(err)
    }
    nonce, _ := client.PendingNonceAt(context.Background(), Key.Address)

    auth.Nonce = big.NewInt(int64(nonce))
    auth.GasPrice = big.NewInt(0)
    auth.GasLimit = uint64(210000)

    address, tx, instance, err := DeployStorage(auth, client)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Contract pending deploy:0x%x\n", address)
    fmt.Printf("Transaction waiting to be mined:0x%x\n\n", tx.Hash())

    time.Sleep(25000 * time.Millisecond)

    value, err := instance.Retrieve(nil)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Vaule:", value)

    }

the DeployStorage was produced by the Storage.sol , and I have complie the contract code, enter image description here

the Storage.sol code is

// SPDX-License-Identifier: GPL-3.0

pragma solidity >0.7.0 < 0.9.0;
/**
* @title Storage
* @dev store or retrieve variable value
*/

contract Storage {

    uint256 value;

    function store(uint256 number) public{
        value = number;
    }

    function retrieve() public view returns (uint256){
        return value;
    }
}

when I go run *.go, it returns

enter image description here

so I use eth.getTransactionReceipt to trace this tx of contract creation, and I found its transactions status is 0x0, which means it failed to complete this transaction? And it can be still found in the block, but it failed to create this contract, so what's wrong with my work? how can I successffully deploy a smart contract on my private chain?

3
  • Do not share text as image. Aug 23 at 6:54
  • sorry, I just wanna show what happened in my code@Itération122442
    – jds250
    Aug 23 at 7:45
  • 1
    And it is alright. But provide it as text, not as image. Aug 23 at 8:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.