Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

near_api

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

near_api

  • 0.4.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

tests

NearApi

Near Protocol API ruby library

Installation

Add this line to your application's Gemfile:

gem 'near_api'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install near_api

Configuration

Via ENV variables:

  • NEAR_NODE_URL RPC node url (for ex. https://rpc.mainnet.near.org)
  • NEAR_SIGNER_ID account name for transactions and view_access_key requests (account_id in .near-credentials)
  • NEAR_KEYPAIR base58 encoded private + public keys (ed25519:4556s... in .near-credentials named as private_key ) if no private key is available public key can be specified as NEAR_PUBLIC_KEY for view requests

Via explicit params: example:

key = NearApi::Key.new('account_id.testnet', key_pair: 'ed25519:4556s...')
config = NearApi::Config.new(node_url: 'https://rpc.testnet.near.org') 
NearApi::Transaction.new(..., key: key, config: config)

Usage

Operations:

View

NearApi::Api instance view methods:

example:

NearApi::Api.new.view_access_key('account_id.testnet')

Response: hash as described in NEAR Protocol JS API

Other methods can be called as:

NearApi::Api.new.json_rpc('EXPERIMENTAL_changes', {
  "changes_type": "single_access_key_changes",
  "keys": [
    {
      "account_id": "example-acct.testnet",
      "public_key": "ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM"
    }
  ],
  "finality": "final"
}
)
Smart contract view function

query smart contract

NearApi::Query.new.call(
  'account_id.testnet',
  'get_num',
  {}
)

Transaction

NearApi::Transaction.new(
  'account_id.testnet', # Transaction call receiver
  [NearApi::Actions::FunctionCall.new('increment', {})], # Array of Actions 
  key: key, # Optional key 
  config: config # Optional config
).call

The example above is waiting for transaction complete

To send transaction async:

NearApi::Transaction.new(...).async

Transaction has one or many actions Actions:

  • Create Account
  • Deploy Contract
  • Function Call
  • Transfer
  • Stake
  • Add Key
  • Delete Key
  • Delete Account

Specs

Transaction status

Transaction_status

NearApi::Status.new.transaction_status(transaction_hash)

Transaction Status with Receipts

NearApi::Status.new.final_transaction_status(transaction_hash)
External Signing

To sign transaction with external signing service (dedicated secure service or hardware ledger)

transaction = NearApi::Transaction.new(...)
digest = transaction.message.digest
# sign with external service 
signature = Ed25519::SigningKey.from_keypair(bytestring).sign(digest)
transaction.call_api('broadcast_tx_commit', transaction.message.message, signature)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/near-rails-guide/near_api

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 07 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc