99 "strings"
1010 "time"
1111
12+ "github.com/ethereum/go-ethereum/ethclient"
13+
1214 "github.com/ethereum/go-ethereum/common"
1315 "github.com/ethereum/go-ethereum/crypto"
1416
@@ -59,7 +61,7 @@ func deployEvmContract(bytecode string, cmd *cobra.Command) {
5961 txData := ethtypes.LegacyTx {
6062 Nonce : nonce ,
6163 GasPrice : big .NewInt (20_000_000_000 ),
62- Gas : 2_000_000 ,
64+ Gas : 4_000_000 ,
6365 To : nil ,
6466 Data : deploymentBytes ,
6567 Value : common .Big0 ,
@@ -77,27 +79,29 @@ func deployEvmContract(bytecode string, cmd *cobra.Command) {
7779 err = signedTx .EncodeRLP (& buf )
7880 utils .ExitOnErr (err , "failed to encode tx" )
7981
82+ fmt .Println ("Tx hash" , signedTx .Hash ())
83+
8084 err = ethClient8545 .SendTransaction (context .Background (), signedTx )
8185 utils .ExitOnErr (err , "failed to send tx" )
8286
83- fmt .Println ("Tx hash" , signedTx .Hash ())
87+ if tx := waitForEthTx (ethClient8545 , signedTx .Hash ()); tx != nil {
88+ fmt .Println ("New contract deployed at:" )
89+ } else {
90+ fmt .Println ("Timed-out waiting for tx to be mined, contract may have been deployed." )
91+ fmt .Println ("Expected contract address:" )
92+ }
93+ fmt .Println (newContractAddress )
94+ }
8495
85- var found bool
96+ func waitForEthTx ( ethClient8545 * ethclient. Client , txHash common. Hash ) * ethtypes. Transaction {
8697 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
98+ tx , _ , err := ethClient8545 .TransactionByHash (context .Background (), txHash )
99+ if err == nil && tx != nil {
100+ return tx
91101 }
92102
93103 time .Sleep (time .Second )
94104 }
95105
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- }
102- fmt .Println (newContractAddress )
106+ return nil
103107}
0 commit comments