@@ -58,17 +58,31 @@ def deploy_args(params)
58
58
end
59
59
60
60
def send_transaction ( tx_args )
61
- if key
62
- Eth . configure { |c | c . chain_id = @client . net_version [ "result" ] . to_i }
63
- tx = Eth ::Tx . new ( { from : key . address , to : main_address , value : value , data : data , nonce : 0 , gas_limit : 1_000_000 , gas_price : gas_price } )
64
- tx . sign key
65
- else
66
61
@client . eth_send_transaction ( tx_args ) [ "result" ]
67
- end
62
+ end
63
+
64
+ def send_raw_transaction ( payload , to = nil )
65
+ Eth . configure { |c | c . chain_id = @client . get_chain }
66
+ args = {
67
+ from : key . address ,
68
+ value : 0 ,
69
+ data : payload ,
70
+ nonce : @client . get_nonce ( key . address ) ,
71
+ gas_limit : 4_000_000 ,
72
+ gas_price : 20_000_000_000
73
+ }
74
+ args [ :to ] = to if to
75
+ tx = Eth ::Tx . new ( args )
76
+ tx . sign key
77
+ @client . eth_send_raw_transaction ( tx . hex ) [ "result" ]
68
78
end
69
79
70
80
def deploy ( *params )
71
- tx = send_transaction ( deploy_args ( params ) )
81
+ if key
82
+ tx = send_raw_transaction ( deploy_payload ( params ) )
83
+ else
84
+ tx = send_transaction ( deploy_args ( params ) )
85
+ end
72
86
tx_failed = tx . nil? || tx == "0x0000000000000000000000000000000000000000000000000000000000000000"
73
87
raise IOError , "Failed to deploy, did you unlock #{ sender } account? Transaction hash: #{ tx } " if tx_failed
74
88
@deployment = Ethereum ::Deployment . new ( tx , @client )
@@ -113,7 +127,11 @@ def call(fun, *args)
113
127
end
114
128
115
129
def transact ( fun , *args )
116
- tx = send_transaction ( call_args ( fun , args ) )
130
+ if key
131
+ tx = send_raw_transaction ( call_payload ( fun , args ) , address )
132
+ else
133
+ tx = send_transaction ( call_args ( fun , args ) )
134
+ end
117
135
return Ethereum ::Transaction . new ( tx , @client , call_payload ( fun , args ) , args )
118
136
end
119
137
@@ -170,6 +188,7 @@ def build
170
188
class_methods = Class . new do
171
189
extend Forwardable
172
190
def_delegators :parent , :deploy_payload , :deploy_args , :call_payload , :call_args
191
+ def_delegators :parent , :signed_deploy , :key , :key=
173
192
def_delegators :parent , :gas , :gas_price , :gas= , :gas_price=
174
193
def_delegators :parent , :abi , :deployment , :events
175
194
def_delegators :parent , :estimate , :deploy , :deploy_and_wait
0 commit comments