Skip to content

Commit 45b72fe

Browse files
committed
add check contract deployment
1 parent 24b1d0d commit 45b72fe

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

cmd/tx/deploy-contract.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"math/big"
99
"strings"
10+
"time"
1011

1112
"github.com/ethereum/go-ethereum/common"
1213
"github.com/ethereum/go-ethereum/crypto"
@@ -76,12 +77,27 @@ func deployEvmContract(bytecode string, cmd *cobra.Command) {
7677
err = signedTx.EncodeRLP(&buf)
7778
utils.ExitOnErr(err, "failed to encode tx")
7879

79-
rawTxRLPHex := hex.EncodeToString(buf.Bytes())
80-
fmt.Printf("RawTx: 0x%s\n", rawTxRLPHex)
81-
8280
err = ethClient8545.SendTransaction(context.Background(), signedTx)
8381
utils.ExitOnErr(err, "failed to send tx")
8482

85-
fmt.Println("New contract deployed at")
83+
fmt.Println("Tx hash", signedTx.Hash())
84+
85+
var found bool
86+
for try := 1; try <= 6; try++ {
87+
txByHash, pending, err := ethClient8545.TransactionByHash(context.Background(), signedTx.Hash())
88+
if err == nil && !pending && txByHash != nil {
89+
found = true
90+
break
91+
}
92+
93+
time.Sleep(time.Second)
94+
}
95+
96+
if found {
97+
fmt.Println("New contract deployed at:")
98+
} else {
99+
fmt.Println("Timed-out waiting for tx to be mined, contract may have been deployed.")
100+
fmt.Println("Expected contract address:")
101+
}
86102
fmt.Println(newContractAddress)
87103
}

0 commit comments

Comments
 (0)