Class: NEAR::CLI

Inherits:
Object
  • Object
show all
Includes:
Account, Config, Contract, Staking, Tokens, Transaction
Defined in:
lib/near/cli.rb,
lib/near/cli.rb

Defined Under Namespace

Modules: Account, Config, Contract, Staking, Tokens, Transaction Classes: Error, ExecutionError, ProgramNotFoundError

Constant Summary collapse

NEAR_ENV =
ENV['NEAR_ENV'] || 'testnet'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Transaction

#construct_transaction, #reconstruct_transaction, #send_meta_transaction, #send_signed_transaction, #sign_transaction, #view_status

Methods included from Contract

#call_function, #deploy_contract, #download_wasm, #view_call, #view_storage, #view_storage_base64

Methods included from Tokens

#send_near, #view_near_balance

Methods included from Account

#add_full_access_key, #add_function_call_key, #create_account_with_faucet, #create_account_with_funding, #create_implicit_account, #delete_account, #delete_key, #import_account_with_private_key, #import_account_with_seed_phrase, #list_keys, #make_storage_deposit, #view_account_summary, #view_storage_balance, #withdraw_storage_deposit

Constructor Details

#initialize(path: self.class.find_program, network: NEAR_ENV) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • path (String, #to_s) (defaults to: self.class.find_program)
  • network (Network, #to_s) (defaults to: NEAR_ENV)


43
44
45
# File 'lib/near/cli.rb', line 43

def initialize(path: self.class.find_program, network: NEAR_ENV)
  @path, @network = path.to_s, network.to_s
end

Class Method Details

.find_programObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/near/cli.rb', line 24

def self.find_program
  return ENV['NEAR_CLI'] if ENV['NEAR_CLI']

  # First, check `$HOME/.cargo/bin/near`:
  path = File.expand_path('~/.cargo/bin/near')
  return path if File.executable?(path)

  # Next, check `$PATH`:
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    path = File.join(path, 'near')
    return path if File.executable?(path)
  end

  raise ProgramNotFoundError
end

Instance Method Details

#versionString

Returns:

  • (String)


49
50
51
# File 'lib/near/cli.rb', line 49

def version
  self.execute('--version').first.strip
end