Module: NEAR::CLI::Account

Included in:
NEAR::CLI
Defined in:
lib/near/cli/account.rb

Overview

Instance Method Summary collapse

Instance Method Details

#add_full_access_key(account_id, public_key) ⇒ String

Adds a full access key to an account.

Parameters:

  • account_id (String)
  • public_key (String)

Returns:

  • (String)


161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/near/cli/account.rb', line 161

def add_full_access_key(, public_key)
  stdout, stderr = execute(
    'account',
    'add-key', ,
    'grant-full-access',
    'use-manually-provided-public-key', public_key,
    'network-config', @network,
    'sign-with-keychain',
    'send'
  )
  stderr
end

#add_function_call_key(account_id, public_key, receiver_id, method_names, allowance) ⇒ String

Adds a function call access key to an account.

Parameters:

  • account_id (String)
  • public_key (String)
  • receiver_id (String)
  • method_names (Array<String>)
  • allowance (String)

Returns:

  • (String)


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/near/cli/account.rb', line 183

def add_function_call_key(, public_key, receiver_id, method_names, allowance)
  stdout, stderr = execute(
    'account',
    'add-key', ,
    'grant-function-call-access',
    '--allowance', allowance,
    '--receiver-account-id', receiver_id,
    '--method-names', method_names.join(', '),
    'use-manually-provided-public-key', public_key,
    'network-config', @network,
    'sign-with-keychain',
    'send'
  )
  stderr
end

#create_account_with_faucet(new_account, public_key: nil) ⇒ String

Creates a new account sponsored by the faucet service.

Parameters:

  • new_account (NEAR::Account, #to_s)
  • public_key (String, nil) (defaults to: nil)

Returns:

  • (String)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/near/cli/account.rb', line 76

def (, public_key: nil)
  stdout, stderr = execute(
    'account',
    'create-account',
    'sponsor-by-faucet-service', .to_s,
    *case public_key
      when nil then ['autogenerate-new-keypair', 'save-to-keychain']
      when String then ['use-manually-provided-public-key', public_key]
      when Array then public_key
      else raise ArgumentError
    end,
    'network-config', @network,
    'create'
  )
  stderr
end

#create_account_with_funding(new_account, signer:, public_key: nil, deposit: nil) ⇒ String

Creates a new account funded by another account.

Parameters:

  • new_account (NEAR::Account, #to_s)
  • signer (NEAR::Account, #to_s)

    Account that signs & funds the transaction

  • public_key (String, nil) (defaults to: nil)
  • deposit (NEAR::Balance, #to_s) (defaults to: nil)

    Amount of NEAR to attach

Returns:

  • (String)


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/near/cli/account.rb', line 101

def (, signer:, public_key: nil, deposit: nil)
  stdout, stderr = execute(
    'account',
    'create-account',
    'fund-myself', .to_s, (deposit ? deposit.to_s : '0') + ' NEAR',
    *case public_key
      when nil then ['autogenerate-new-keypair', 'save-to-keychain']
      when String then ['use-manually-provided-public-key', public_key]
      when Array then public_key
      else raise ArgumentError
    end,
    'sign-as', signer.to_s,
    'network-config', @network,
    'sign-with-keychain',
    'send'
  )
  stderr
end

#create_implicit_account(save_path) ⇒ String

Creates an implicit account.

Parameters:

  • save_path (String)

Returns:

  • (String)


125
126
127
128
129
130
131
132
133
134
# File 'lib/near/cli/account.rb', line 125

def (save_path)
  stdout, stderr = execute(
    'account',
    'create-account',
    'fund-later',
    'use-auto-generation',
    'save-to-folder', save_path
  )
  stderr
end

#delete_account(account, beneficiary: nil) ⇒ String

Deletes an account and transfers remaining balance to beneficiary.

Parameters:

Returns:

  • (String)


142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/near/cli/account.rb', line 142

def (, beneficiary: nil)
   = NEAR::Account.parse()
  stdout, stderr = execute(
    'account',
    'delete-account', .to_s,
    'beneficiary', (beneficiary || .parent).to_s,
    'network-config', @network,
    'sign-with-keychain',
    'send'
  )
  stderr
end

#delete_key(account_id, public_key) ⇒ String

Deletes an access key from an account.

Parameters:

  • account_id (String)
  • public_key (String)

Returns:

  • (String)


205
206
207
208
209
210
211
212
213
214
215
# File 'lib/near/cli/account.rb', line 205

def delete_key(, public_key)
  stdout, stderr = execute(
    'account',
    'delete-key', ,
    public_key,
    'network-config', @network,
    'sign-with-keychain',
    'send'
  )
  stderr
end

#import_account_with_private_key(private_key) ⇒ String

Imports an existing account using a private key.

Parameters:

  • private_key (String)

Returns:

  • (String)


60
61
62
63
64
65
66
67
68
# File 'lib/near/cli/account.rb', line 60

def (private_key)
  _, stderr = execute(
    'account',
    'import-account',
    'using-private-key', private_key,
    'network-config', @network
  )
  stderr
end

#import_account_with_seed_phrase(seed_phrase, hd_path: "m/44'/397'/0'") ⇒ String

Imports an existing account using a seed phrase.

Parameters:

  • seed_phrase (String)
  • hd_path (String) (defaults to: "m/44'/397'/0'")

Returns:

  • (String)


44
45
46
47
48
49
50
51
52
53
# File 'lib/near/cli/account.rb', line 44

def (seed_phrase, hd_path: "m/44'/397'/0'")
  _, stderr = execute(
    'account',
    'import-account',
    'using-seed-phrase', seed_phrase,
    '--seed-phrase-hd-path', hd_path,
    'network-config', @network
  )
  stderr
end

#list_keys(account_id, block: :now) ⇒ String

Lists access keys for an account.

Parameters:

  • account_id (String)
  • block (Block, Integer, String, Symbol) (defaults to: :now)

Returns:

  • (String)


28
29
30
31
32
33
34
35
36
# File 'lib/near/cli/account.rb', line 28

def list_keys(, block: :now)
  stdout, _ = execute(
    'account',
    'list-keys', ,
    'network-config', @network,
    *block_args(block)
  )
  stdout
end

#make_storage_deposit(contract_id, account_id, deposit, sign_as) ⇒ String

Makes a storage deposit for an account.

Parameters:

  • contract_id (String)
  • account_id (String)
  • deposit (String)
  • sign_as (String)

Returns:

  • (String)


243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/near/cli/account.rb', line 243

def make_storage_deposit(contract_id, , deposit, sign_as)
  stdout, stderr = execute(
    'account',
    'manage-storage-deposit', contract_id,
    'deposit', , deposit,
    'sign-as', sign_as,
    'network-config', @network,
    'sign-with-keychain',
    'send'
  )
  stderr
end

#view_account_summary(account_id, block: :now) ⇒ String

Views properties for an account.

Parameters:

  • account_id (String)
  • block (Block, Integer, String, Symbol) (defaults to: :now)

Returns:

  • (String)


12
13
14
15
16
17
18
19
20
# File 'lib/near/cli/account.rb', line 12

def (, block: :now)
  stdout, _ = execute(
    'account',
    'view-account-summary', ,
    'network-config', @network,
    *block_args(block)
  )
  stdout
end

#view_storage_balance(contract_id, account_id, block: :now) ⇒ String

Views storage balance for an account.

Parameters:

  • contract_id (String)
  • account_id (String)
  • block (Block, Integer, String, Symbol) (defaults to: :now)

Returns:

  • (String)


224
225
226
227
228
229
230
231
232
233
# File 'lib/near/cli/account.rb', line 224

def view_storage_balance(contract_id, , block: :now)
  stdout, _ = execute(
    'account',
    'manage-storage-deposit', contract_id,
    'view-balance', ,
    'network-config', @network,
    *block_args(block)
  )
  stdout
end

#withdraw_storage_deposit(contract_id, amount, account_id) ⇒ String

Withdraws storage deposit for an account.

Parameters:

  • contract_id (String)
  • amount (String)
  • account_id (String)

Returns:

  • (String)


263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/near/cli/account.rb', line 263

def withdraw_storage_deposit(contract_id, amount, )
  stdout, stderr = execute(
    'account',
    'manage-storage-deposit', contract_id,
    'withdraw', amount,
    'sign-as', ,
    'network-config', @network,
    'sign-with-keychain',
    'send'
  )
  stderr
end