Skip to main content

Import


createNearBuilder

Factory function to create a NEAR transaction builder.

Signature

Parameters

config
NearBuilderConfig
required

Returns

NearBuilder
object
A builder instance with methods for building NEAR transactions.

Example


NearBuilder Methods

buildTransfer

Build an unsigned transfer transaction to bridge tokens from NEAR.

Signature

Parameters

validated
ValidatedTransfer
required
The validated transfer from bridge.validateTransfer().
signerId
string
required
The NEAR account ID that will sign the transaction.

Returns

NearUnsignedTransaction
object
An unsigned transaction ready to be signed and sent.

Example


buildStorageDeposit

Build a transaction to deposit storage on the bridge contract.

Signature

Parameters

signerId
string
required
The NEAR account ID that will sign and pay for storage.
amount
bigint
required
The amount of NEAR (in yoctoNEAR) to deposit for storage.

Returns

NearUnsignedTransaction
object
An unsigned storage deposit transaction.

Example


getRequiredStorageDeposit

Get the required storage deposit for an account on the bridge contract. Makes view calls to check current balance vs required amounts.

Signature

Parameters

accountId
string
required
The NEAR account ID to check storage for.

Returns

bigint
bigint
Amount of additional storage deposit needed in yoctoNEAR. Returns 0n if sufficient storage exists.

Example


isTokenStorageRegistered

Check if a token has storage registered for the bridge contract. If not, the bridge needs storage_deposit on the token before receiving transfers.

Signature

Parameters

tokenId
string
required
The token contract ID to check.

Returns

boolean
boolean
true if bridge has storage, false if storage_deposit is needed.

Example


buildTokenStorageDeposit

Build a storage deposit transaction on a token contract for the bridge. This is needed before the bridge can receive tokens.

Signature

Parameters

tokenId
string
required
The token contract ID to register storage on.
signerId
string
required
The NEAR account ID paying for storage.

Returns

Promise<NearUnsignedTransaction>
Promise
An unsigned transaction for storage_deposit on the token contract.

Example


buildFinalization

Build a transaction to finalize an incoming transfer to NEAR.

Signature

Parameters

params
FinalizationParams
required

Returns

NearUnsignedTransaction
object
An unsigned finalization transaction.

Example


buildLogMetadata

Build a transaction to log token metadata on the bridge. This is the first step in registering a new token.

Signature

Parameters

token
string
required
The NEAR token contract ID (e.g., "wrap.near").
signerId
string
required
The NEAR account ID that will sign the transaction.

Returns

NearUnsignedTransaction
object
An unsigned log metadata transaction.

Example


buildDeployToken

Build a transaction to deploy a token on a destination chain. Used for registering NEAR tokens on other chains.

Signature

Parameters

destinationChain
ChainKind
required
The destination chain to deploy the token on.
proverArgs
Uint8Array
required
Serialized prover arguments (use serializeEvmProofArgs or serializeWormholeProofArgs).
signerId
string
required
The NEAR account ID that will sign the transaction.
deposit
bigint
required
The NEAR deposit required for deployment.

Returns

NearUnsignedTransaction
object
An unsigned deploy token transaction.

Example


buildBindToken

Build a transaction to bind a token from a source chain. Used for registering foreign tokens on NEAR.

Signature

Parameters

sourceChain
ChainKind
required
The source chain where the token originates.
proverArgs
Uint8Array
required
Serialized prover arguments.
signerId
string
required
The NEAR account ID that will sign the transaction.
deposit
bigint
required
The NEAR deposit required for binding.

Returns

NearUnsignedTransaction
object
An unsigned bind token transaction.

Example


buildSignTransfer

Build a transaction to request MPC signature for a transfer. Used by relayers.

Signature

Parameters

transferId
TransferId
required
feeRecipient
string
required
The NEAR account to receive the relayer fee.
fee
object
required
signerId
string
required
The NEAR account ID that will sign the transaction.

Returns

NearUnsignedTransaction
object
An unsigned sign transfer transaction.

Example


buildFastFinTransfer

Build a transaction for fast finalization of a transfer. Used by relayers to provide immediate liquidity.

Signature

Parameters

params
FastFinTransferParams
required
signerId
string
required
The NEAR account ID that will sign the transaction.

Returns

NearUnsignedTransaction
object
An unsigned fast finalization transaction.

Example


serializeEvmProofArgs

Serialize EVM proof arguments for the prover contract.

Signature

Parameters

args
EvmVerifyProofArgs
required

Returns

Uint8Array
Uint8Array
Borsh-serialized proof arguments.

Example


serializeWormholeProofArgs

Serialize Wormhole VAA proof arguments for the prover contract.

Signature

Parameters

args
WormholeVerifyProofArgs
required

Returns

Uint8Array
Uint8Array
Borsh-serialized proof arguments.

Example


UTXO Methods (BTC/Zcash)

Methods for interacting with the Bitcoin and Zcash UTXO connectors on NEAR.

buildUtxoDepositFinalization

Build a transaction to finalize a UTXO deposit on NEAR. Calls verify_deposit on the connector contract.

Signature

Parameters

params
UtxoDepositFinalizationParams
required

Returns

NearUnsignedTransaction
object
An unsigned verify_deposit transaction.

buildUtxoWithdrawalInit

Build a transaction to initiate a UTXO withdrawal from NEAR. Calls ft_transfer_call on the nBTC/nZEC token.

Signature

Parameters

params
UtxoWithdrawalInitParams
required

Returns

NearUnsignedTransaction
object
An unsigned ft_transfer_call transaction.

buildUtxoWithdrawalVerify

Build a transaction to verify a UTXO withdrawal on NEAR. Calls btc_verify_withdraw on the connector.

Signature

Parameters

params
UtxoWithdrawalVerifyParams
required

Returns

NearUnsignedTransaction
object
An unsigned btc_verify_withdraw transaction.

getUtxoConnectorAddress

Get the UTXO connector contract address for a chain.

Signature

Parameters

chain
'btc' | 'zcash'
required
The UTXO chain.

Returns

string
string
The connector contract address.

getUtxoTokenAddress

Get the UTXO token contract address for a chain.

Signature

Parameters

chain
'btc' | 'zcash'
required
The UTXO chain.

Returns

string
string
The token contract address (nBTC or nZEC).

getUtxoConnectorConfig

Get the UTXO connector configuration from the contract.

Signature

Parameters

chain
'btc' | 'zcash'
required
The UTXO chain.

Returns

Promise<UtxoConnectorConfig>
Promise

getUtxoAvailableOutputs

Get available UTXOs from the connector contract.

Signature

Parameters

chain
'btc' | 'zcash'
required
The UTXO chain.

Returns

Promise<UTXO[]>
Promise
Array of available UTXOs for withdrawal.

getUtxoTokenBalance

Get the nBTC/nZEC token balance for an account.

Signature

Parameters

chain
'btc' | 'zcash'
required
The UTXO chain.
accountId
string
required
NEAR account to check balance for.

Returns

Promise<bigint>
Promise
Token balance in satoshis/zatoshis.

calculateUtxoWithdrawalFee

Calculate the bridge fee for a UTXO withdrawal.

Signature

Parameters

chain
'btc' | 'zcash'
required
The UTXO chain.
amount
bigint
required
Withdrawal amount in satoshis/zatoshis.

Returns

Promise<bigint>
Promise
Bridge fee amount.

Shim Functions

Functions to convert SDK transactions to library-specific formats.

toNearKitTransaction

Convert a NearUnsignedTransaction to a near-kit TransactionBuilder. near-kit handles nonce, blockHash, and signing automatically.

Signature

Parameters

near
Near
required
A configured near-kit Near instance.
unsigned
NearUnsignedTransaction
required
The unsigned transaction from the builder.

Returns

TransactionBuilder
TransactionBuilder
A near-kit TransactionBuilder that can be sent with .send() or built with .build().

Example


toNearApiJsActions

Convert NearUnsignedTransaction actions to @near-js/transactions Action array. Use this with Account.signAndSendTransaction().

Signature

Parameters

unsigned
NearUnsignedTransaction
required
The unsigned transaction from the builder.

Returns

Action[]
Action[]
Array of Action objects for use with @near-js/accounts.

Example


sendWithNearApiJs

Convenience wrapper that converts and sends a transaction using @near-js/accounts.

Signature

Parameters

account
Account
required
A @near-js/accounts Account instance with signer configured.
unsigned
NearUnsignedTransaction
required
The unsigned transaction from the builder.

Returns

Promise<FinalExecutionOutcome>
Promise
The transaction execution outcome.

Example


MPCSignature Class

Class representing an MPC signature from the NEAR bridge contract.

Constructor

Properties

big_r
AffinePoint
The R component of the signature as an affine point.
s
Scalar
The S component of the signature.
recovery_id
number
The recovery ID (0 or 1).

Methods

toBytes

Convert the signature to bytes for use on Solana or EVM.
forEvm
boolean
If true, adds 27 to recovery_id for EVM compatibility.

fromRaw (static)

Create an MPCSignature from raw contract log data.

Example


calculateStorageAccountId

Calculate the storage account ID for a transfer message. This replicates the on-chain calculation.

Signature

Parameters

transferMessage
TransferMessageForStorage
required

Returns

string
string
The storage account ID as a hex string.

Example


Types

NearUnsignedTransaction

The unsigned transaction format returned by the builder.

NearAction

An action within a NEAR transaction.

TransferId

Identifier for a cross-chain transfer.

TransferFee

Fee structure for transfers.

StorageDepositAction

Action for depositing storage during finalization.

UtxoPostAction

Post-action to execute after UTXO deposit is finalized.

UtxoBridgeFee

Bridge fee configuration.

UTXO

UTXO structure for Bitcoin/Zcash operations.

Enums

ProofKind

Types of proofs for finalization and token operations.

Constants

GAS

Pre-defined gas amounts for NEAR transactions.

DEPOSIT

Pre-defined deposit amounts.

Borsh Schemas

The package exports Borsh serialization schemas for advanced use cases.
These schemas use the @zorsh/zorsh library and can be used for custom serialization: