3
3
require 'json'
4
4
5
5
def library_code
6
- 'function create(abiDefinition) { return web3.eth.contract(abiDefinition);}function deploy(account, gas, contract, code, input) { if (typeof(input)===\'undefined\') input = null; var instance = contract.new(input,{from:account, data: code, gas: gas}, function (e, contract) { if(!e) { if(!contract.address) { console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined..."); } else { console.log("Contract mined! Address: " + contract.address); } } else { console.log(e) } }); return instance;}function watcher(error, result) { if (!error) { console.log("Result"); console.log(JSON.stringify(result)); return; } console.log("Error" + error);}function call(account, gas, func, input) { if (typeof(input)===\'undefined\') input = null; func.sendTransaction(input, gas, {from:account}, watcher);}'
6
+ 'function create(abiDefinition) { return web3.eth.contract(abiDefinition);}function deploy(account, value, gas, contract, code, input) { if (typeof(input)===\'undefined\') input = null; var instance = contract.new(input,{from:account, value: value, data: code, gas: gas}, function (e, contract) { if(!e) { if(!contract.address) { console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined..."); } else { console.log("Contract mined! Address: " + contract.address); } } else { console.log(e) } }); return instance;}function watcher(error, result) { if (!error) { console.log("Result"); console.log(JSON.stringify(result)); return; } console.log("Error" + error);}function call(account, gas, func, input) { if (typeof(input)===\'undefined\') input = null; func.sendTransaction(input, gas, {from:account}, watcher);}'
7
7
end
8
8
9
9
@@ -51,6 +51,15 @@ def get_gas
51
51
gas
52
52
end
53
53
54
+ def get_value
55
+ gas = -1
56
+ while gas < 0
57
+ puts "Enter Value To Be Transferred: "
58
+ gas = $stdin. gets . to_i
59
+ end
60
+ gas
61
+ end
62
+
54
63
file_name = ARGV [ 0 ]
55
64
code = File . read ( file_name ) . gsub ( "\n " , '' )
56
65
@@ -64,15 +73,18 @@ contract_variable_name = "#{current_contract}Contract"
64
73
contract_instance_variable_name = "#{ current_contract } "
65
74
66
75
gas = get_gas
76
+ value = get_value
67
77
input = get_input
68
78
69
79
File . open ( javascript_file_name , 'w' ) do |f |
70
80
f . write ( "#{ library_code } ;\n var #{ compiled_variable_name } = #{ compiled_object . to_json } ;" )
71
81
f . write ( "#{ contract_variable_name } = create(#{ compiled_variable_name } .#{ current_contract } .info.abiDefinition);" )
72
- f . write ( "#{ contract_instance_variable_name } = deploy(eth.coinbase,#{ gas } ,#{ contract_variable_name } ,#{ compiled_variable_name } .#{ current_contract } .code,#{ input } );" )
82
+ f . write ( "#{ contract_instance_variable_name } = deploy(eth.coinbase,#{ value } , #{ gas } ,#{ contract_variable_name } ,#{ compiled_variable_name } .#{ current_contract } .code,#{ input } );" )
73
83
f . write ( "console.log('Compiled Object : #{ compiled_variable_name } ');" )
74
84
f . write ( "console.log('Contract : #{ contract_variable_name } ');" )
75
85
f . write ( "console.log('Contract Instance : #{ contract_instance_variable_name } ');" )
76
86
end
77
87
78
88
puts "loadScript('#{ `pwd` } /#{ javascript_file_name } ')" . gsub ( "\n " , '' )
89
+ # ~> -:64:in `read': no implicit conversion of nil into String (TypeError)
90
+ # ~> from -:64:in `<main>'
0 commit comments