NeoLine
English
English
  • Welcome to NeoLine
  • 🌵Download NeoLine Wallet
    • Mobile
      • Download iOS Version
      • Download Android Version
    • Google Chrome Extension
      • Download Google Chrome Extension
  • 🧩Create and Manage Neo X Wallet
    • Create Neo X (EVM) Wallet
    • Import Neo X (EVM) wallet
    • How to Bridge GAS Using the NeoLine Chrome Extension?
    • How to add and switch networks?
    • About NeoLine Activity
  • 🙂N3 Wallet
    • Neo N3 Wallet User Guide
      • Neo N3 Wallet | Mobile
      • Neo N3 Wallet | NeoLine Chrome Extension
    • Neo N3 Migration Guide
      • Neo N3 Migration Guide | Mobile
      • Neo N3 Migration Guide | NeoLine Chrome Extension
  • 🔒Hardware Wallet
    • Ledger Hardware Wallet
  • 🌈Getting Started
    • How to Securely and Correctly Backup Your Wallet?
    • One Pass Setting for NeoLine Extension Wallet
    • How to Use the Address Book?
    • How to Speed Up or Cancel a Pending Transaction?
    • How to Delete Unused Wallet Accounts in the NeoLine Wallet?
    • Manage Assets
      • How to Add/Manage Assets?
      • How to Add NFTs
      • How to Use NeoLine Wallet for Transfer and Receive
      • How to Transfer to Other Wallets/Exchanges
    • FAQ
  • Reference
    • Neo3 provider API
      • Read Methods
        • getProvider
        • getBalance
        • getStorage
        • invokeRead
        • invokeReadMulti
        • verifyMessage
        • verifyMessageV2
        • getBlock
        • getTransaction
        • getApplicationLog
        • pickAddress
        • AddressToScriptHash
        • ScriptHashToAddress
      • Write Methods
        • send
        • invoke
        • invokeMultiple
        • signMessage
        • signMessageV2
        • signMessageWithoutSalt
        • signMessageWithoutSaltV2
        • signTransaction
        • switchWalletNetwork
        • switchWalletAccount
      • Common Methods
        • getNetworks
        • getAccount
        • getPublicKey
      • Common Events
        • READY
        • ACCOUNT_CHANGED
        • CONNECTED
        • DISCONNECTED
        • NETWORK_CHANGED
        • BLOCK_HEIGHT_CHANGED
        • TRANSACTION_CONFIRMED
      • Event Methods
        • addEventListener
        • removeEventListener
      • Errors
        • Errors
    • Neo2 provider API
      • Read Methods
        • getProvider
        • getNetworks
        • getAccount
        • getPublicKey
        • getBalance
        • getStorage
        • invokeRead
        • verifyMessage
        • getBlock
        • getTransaction
        • getApplicationLog
      • Write Methods
        • send
        • invoke
        • invokeMulti
        • signMessage
        • deploy
        • switchWalletNetwork
        • switchWalletAccount
      • Events
        • READY
        • ACCOUNT_CHANGED
        • CONNECTED
        • DISCONNECTED
        • NETWORK_CHANGED
        • BLOCK_HEIGHT_CHANGED
        • TRANSACTION_CONFIRMED
      • Event Methods
        • addEventListener
        • removeEventListener
      • Errors
        • Errors
    • Ethereum provider API
    • JSON-RPC API
      • eth_requestAccounts
      • eth_accounts
      • eth_chainId
      • personal_sign
      • eth_signTypedData_v4
      • eth_sendTransaction
      • wallet_addEthereumChain
      • wallet_switchEthereumChain
      • wallet_watchAsset
  • 💬Contact Us
    • Contact Us
由 GitBook 提供支持
在本页
  • Properties
  • isNEOLine
  • Methods
  • request()
  • Events
  • accountsChanged
  • chainChanged
  • Remove event listeners
  • Errors

这有帮助吗?

  1. Reference

Ethereum provider API

上一页Errors下一页JSON-RPC API

最后更新于7个月前

这有帮助吗?

The NeoLine extension wallet injects an Ethereum provider, as specified by, into the browser at window.NEOLineNeoX.

You can use this provider in your dapp to request users' Ethereum accounts, read on-chain data, and have the user sign messages and transactions.

NOTE

NeoLine supports , You can access the provider API using the selected EIP-6963 provider object. Throughout this documentation, we refer to the selected provider using provider.

let provider;
window.addEventListener('eip6963:announceProvider', (event) => {
  if (event.detail.provider.isNEOLine) {
    provider = event.detail.provider;
  }
});
window.dispatchEvent(new Event('eip6963:requestProvider'));

Properties

isNEOLine

This property is true if the user has NeoLine installed, and false otherwise.

Example

provider.isNEOLine // Or window.NEOLineNeoX.isNEOLine if you don't support EIP-6963.

Methods

request()

Parameters

An object containing:

  • params: array or object - (Optional) Parameters of the RPC method. In practice, if a method has parameters, they're almost always of type array.

Returns

A promise that resolves to the result of the RPC method call. If the request fails, the promise rejects with an error.

Example

provider // Or window.NEOLineNeoX if you don't support EIP-6963.
  .request({
    method: "eth_sendTransaction",
    params: [
      {
        from: "0xE45e9AdC2B51514849ea5B38dF37d1a65e6D52f5",
        to: "0x7Cd07BCbcCF30d71E768F5228b56d5B7Cc07f674",
        value: "0x3b9aca00", // 1_000_000_000
      },
    ],
  })
  .then((result) => {
    // The result varies by RPC method.
    // For example, this method returns a transaction hash hexadecimal string upon success.
  })
  .catch((error) => {
    // If the request fails, the Promise rejects with an error.
  })

NeoLine Wallet supports many standardized Ethereum RPC methods, including:

  • eth_sendRawTransaction

  • eth_blockNumber

  • eth_call

  • eth_estimateGas

  • ...

Events

function handleAccountsChanged(accounts) {
  // Handle new accounts, or lack thereof.
}

provider // Or window.NEOLineNeoX if you don't support EIP-6963.
  .on("accountsChanged", handleAccountsChanged)

// Later

provider // Or window.NEOLineNeoX if you don't support EIP-6963.
  .removeListener("accountsChanged", handleAccountsChanged)

accountsChanged

provider // Or window.NEOLineNeoX if you don't support EIP-6963.
  .on("accountsChanged", handler: (accounts: string[]) => void);

chainChanged

provider // Or window.NEOLineNeoX if you don't support EIP-6963.
  .on("chainChanged", handler: (chainId: string) => void);

Remove event listeners

removeListener

Use the removeListener method to remove specific event listeners from an EventEmitter object. In the following example removeListener is used to remove the chainChanged and accountsChanged events:

// Use window.NEOLineNeoX instead of provider if EIP-6963 is not supported.

// Add listeners
provider.on("accountsChanged", updateWallet)
provider.on("chainChanged", updateWalletAndAccounts)

// Remove individual listeners
provider.removeListener("accountsChanged", updateWallet)
provider.removeListener("chainChanged", updateWalletAndAccounts)

Errors

All errors returned by the NeoLine provider follow this interface:

interface ProviderRpcError extends Error {
  message: string
  code: number
  data?: unknown
}

The request() provider method throws errors eagerly. You can use the error code property to determine why the request failed. Common codes and their meaning include:

  • 4001 - The request is rejected by the user.

  • -32602 - The parameters are invalid.

  • -32603 - Internal error.

This method is used to submit to Ethereum using NeoLine.

method: string - The method name.

The following is an example of using request() to call :

The NeoLine provider emits events using the Node.js API. The following is an example of listening to the event.

You should after you're done listening to an event (for example, on component unmount in React).

The provider emits this event when the return value of the RPC method changes. eth_accounts returns either an empty array, or an array that contains the addresses of the accounts the caller is permitted to access with the most recently used account first. Callers are identified by their URL origin, which means that all sites with the same origin share the same permissions.

The provider emits this event when the currently connected chain changes. Listen to this event to .

For the complete list of errors, see and .

EIP-1193
EIP-6963
JSON-RPC API requests
JSON-RPC API
eth_sendTransaction
wallet_addEthereumChain
wallet_switchEthereumChain
wallet_watchAsset
personal_sign
eth_signTypedData_v4
eth_chainId
eth_accounts
eth_requestAccounts
eth_sendTransaction
EventEmitter
accountsChanged
remove listeners
eth_accounts
detect a user's network
EIP-1193
EIP-1474