For the complete documentation index, see llms.txt. This page is also available as Markdown.

API Reference

This page documents the IDapiProvider interface defined by the current NEP-21 proposal.

Provider

Neo.DapiProvider.ready

Wallet providers dispatch this browser event when an IDapiProvider is ready. dApps listen for it and read the provider from event.detail.provider.

Field
Type
Description

detail.provider

IDapiProvider

Provider instance exposed by the wallet.

window.addEventListener("Neo.DapiProvider.ready", (event) => {
  const provider = (event as CustomEvent).detail.provider;
});

Neo.DapiProvider.request

dApps may dispatch this browser event to request a provider.

Field
Type
Description

detail.version

Version

dAPI version requested by the dApp.

window.dispatchEvent(new CustomEvent("Neo.DapiProvider.request", {
  detail: {
    version: "1.0",
  },
}));

If multiple providers respond, the dApp may choose which provider to use.

Provider properties

NEP-21 exposes provider information as properties on the provider object.

Property
Type
Description

name

string

Provider name.

version

Version

Provider version.

dapiVersion

Version

dAPI version. It must currently be "1.0".

compatibility

string[]

Supported standards. It should include "NEP-21" when supported.

connected

boolean

Whether the user has connected their wallet to the dApp.

network

Network

Current network.

supportedNetworks

Network[]

Networks supported by the provider.

icon

string

Provider icon URL. The URL scheme should be https or data.

website

string

Provider website.

extra

any

Additional provider data.

Example provider information:

Account and Authentication

authenticate(payload)

Requests authentication. This is usually used to log in to a website. The authentication process is described in NEP-20.

Parameter
Type
Description

payload

AuthenticationChallengePayload

Authentication challenge payload.

Returns AuthenticationResponsePayload.

Possible errors: UNSUPPORTED, INVALID, TIMEOUT, CANCELED.

Example response:

getAccounts()

Gets the current connected account in the wallet.

Parameters: none.

Returns Account[].

Example response:

pickAddress(prompt?)

Prompts the user to select an account from the wallet and returns the selected address.

Parameter
Type
Description

prompt

string

Optional prompt shown to the user.

Returns Address.

Possible error: CANCELED.

Read Methods

getBalance(asset, account)

Gets the balance of the specified account. The account can be in the wallet or an arbitrary address.

Parameter
Type
Description

asset

UInt160

Asset contract hash.

account

UInt160

Account script hash.

Returns Integer.

Possible errors: INVALID, NOTFOUND, FAILED, RPC_ERROR.

getTokenInfo(hash)

Gets information about a token.

Parameter
Type
Description

hash

UInt160

Token contract hash.

Returns Token.

Possible errors: INVALID, NOTFOUND, FAILED, RPC_ERROR.

call(invocation)

Calls a contract offchain and returns the execution result.

Parameter
Type
Description

invocation

InvocationArguments

Contract call arguments.

Returns InvocationResult.

Possible errors: INVALID, RPC_ERROR.

getBlock(hash)

Gets a block by hash.

Parameter
Type
Description

hash

UInt256

Block hash.

Returns Block.

Possible errors: INVALID, NOTFOUND, RPC_ERROR.

getBlock(index)

Gets a block by index.

Parameter
Type
Description

index

number

Block index.

Returns Block.

Possible errors: INVALID, NOTFOUND, RPC_ERROR.

getBlockCount()

Gets the count of blocks in the blockchain.

Parameters: none.

Returns number.

Possible error: RPC_ERROR.

getTransaction(txid)

Gets a transaction by hash.

Parameter
Type
Description

txid

UInt256

Transaction hash.

Returns Transaction.

Possible errors: INVALID, NOTFOUND, RPC_ERROR.

getApplicationLog(txid)

Gets the application log of a transaction.

Parameter
Type
Description

txid

UInt256

Transaction hash.

Returns ApplicationLog.

Possible errors: INVALID, RPC_ERROR.

getStorage(hash, key)

Gets a storage entry.

Parameter
Type
Description

hash

UInt160

Contract hash.

key

Base64Encoded

Storage key.

Returns Base64Encoded.

Possible errors: INVALID, NOTFOUND, RPC_ERROR.

Write and Signing Methods

send(asset, from, to, amount, data?)

Sends assets to an account and returns the transaction hash.

Parameter
Type
Description

asset

UInt160

Asset contract hash.

from

UInt160

Sender account script hash.

to

UInt160

Recipient account script hash.

amount

Integer

Amount to send.

data

Argument

Optional transfer data.

Returns UInt256.

Possible errors: INVALID, NOTFOUND, FAILED, TIMEOUT, CANCELED, INSUFFICIENT_FUNDS, RPC_ERROR.

invoke(invocations, signers?, attributes?, options?)

Calls one or more contracts onchain and returns the transaction hash.

Parameter
Type
Description

invocations

InvocationArguments[]

Contract calls.

signers

Signer[]

Optional transaction signers.

attributes

TransactionAttribute[]

Optional transaction attributes.

options

TransactionOptions

Optional transaction options.

Returns UInt256.

Possible errors: INVALID, FAILED, TIMEOUT, CANCELED, RPC_ERROR.

makeTransaction(invocations, signers?, attributes?, options?)

Calls one or more contracts onchain and returns the transaction without relaying it.

Parameter
Type
Description

invocations

InvocationArguments[]

Contract calls.

signers

Signer[]

Optional transaction signers.

attributes

TransactionAttribute[]

Optional transaction attributes.

options

TransactionOptions

Optional transaction options.

Returns ContractParametersContext.

Possible errors: INVALID, FAILED, TIMEOUT, CANCELED, RPC_ERROR.

sign(context)

Signs a transaction with the current wallet. This is usually used for multi-signature transactions.

Parameter
Type
Description

context

ContractParametersContext

Transaction context.

Returns ContractParametersContext.

Possible errors: UNSUPPORTED, INVALID, NOTFOUND, TIMEOUT, CANCELED.

signMessage(message, account?, options?)

Signs a message with the specified account. The algorithm is ECDSA with SHA-256.

Parameter
Type
Description

message

string | Base64Encoded

Message to sign.

account

UInt160

Optional account script hash.

options

SignOptions

Optional signing options.

Returns SignedMessage.

Possible errors: INVALID, NOTFOUND, TIMEOUT, CANCELED.

relay(context)

Relays a transaction and returns the transaction hash.

Parameter
Type
Description

context

ContractParametersContext

Transaction context.

Returns UInt256.

Possible errors: INVALID, TIMEOUT, CANCELED, INSUFFICIENT_FUNDS, RPC_ERROR.

Event Methods

on(event, listener)

Adds an event handler.

Parameter
Type
Description

event

EventName

"accountchanged" or "networkchanged".

listener

(e: CustomEvent) => void

Event handler.

removeListener(event, listener)

Removes an event handler.

Parameter
Type
Description

event

EventName

"accountchanged" or "networkchanged".

listener

(e: CustomEvent) => void

Event handler to remove.