Import
createNearBuilder
Factory function to create a NEAR transaction builder.Signature
Parameters
NearBuilderConfig
required
Returns
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
ValidatedTransfer
required
The validated transfer from
bridge.validateTransfer().string
required
The NEAR account ID that will sign the transaction.
Returns
object
An unsigned transaction ready to be signed and sent.
Example
buildStorageDeposit
Build a transaction to deposit storage on the bridge contract.Signature
Parameters
string
required
The NEAR account ID that will sign and pay for storage.
bigint
required
The amount of NEAR (in yoctoNEAR) to deposit for storage.
Returns
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
string
required
The NEAR account ID to check storage for.
Returns
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 needsstorage_deposit on the token before receiving transfers.
Signature
Parameters
string
required
The token contract ID to check.
Returns
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
string
required
The token contract ID to register storage on.
string
required
The NEAR account ID paying for storage.
Returns
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
FinalizationParams
required
Returns
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
string
required
The NEAR token contract ID (e.g.,
"wrap.near").string
required
The NEAR account ID that will sign the transaction.
Returns
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
ChainKind
required
The destination chain to deploy the token on.
Uint8Array
required
Serialized prover arguments (use
serializeEvmProofArgs or serializeWormholeProofArgs).string
required
The NEAR account ID that will sign the transaction.
bigint
required
The NEAR deposit required for deployment.
Returns
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
ChainKind
required
The source chain where the token originates.
Uint8Array
required
Serialized prover arguments.
string
required
The NEAR account ID that will sign the transaction.
bigint
required
The NEAR deposit required for binding.
Returns
object
An unsigned bind token transaction.
Example
buildSignTransfer
Build a transaction to request MPC signature for a transfer. Used by relayers.Signature
Parameters
TransferId
required
string
required
The NEAR account to receive the relayer fee.
object
required
string
required
The NEAR account ID that will sign the transaction.
Returns
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
FastFinTransferParams
required
string
required
The NEAR account ID that will sign the transaction.
Returns
object
An unsigned fast finalization transaction.
Example
serializeEvmProofArgs
Serialize EVM proof arguments for the prover contract.Signature
Parameters
EvmVerifyProofArgs
required
Returns
Uint8Array
Borsh-serialized proof arguments.
Example
serializeWormholeProofArgs
Serialize Wormhole VAA proof arguments for the prover contract.Signature
Parameters
WormholeVerifyProofArgs
required
Returns
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. Callsverify_deposit on the connector contract.
Signature
Parameters
UtxoDepositFinalizationParams
required
Returns
object
An unsigned verify_deposit transaction.
buildUtxoWithdrawalInit
Build a transaction to initiate a UTXO withdrawal from NEAR. Callsft_transfer_call on the nBTC/nZEC token.
Signature
Parameters
UtxoWithdrawalInitParams
required
Returns
object
An unsigned ft_transfer_call transaction.
buildUtxoWithdrawalVerify
Build a transaction to verify a UTXO withdrawal on NEAR. Callsbtc_verify_withdraw on the connector.
Signature
Parameters
UtxoWithdrawalVerifyParams
required
Returns
object
An unsigned btc_verify_withdraw transaction.
getUtxoConnectorAddress
Get the UTXO connector contract address for a chain.Signature
Parameters
'btc' | 'zcash'
required
The UTXO chain.
Returns
string
The connector contract address.
getUtxoTokenAddress
Get the UTXO token contract address for a chain.Signature
Parameters
'btc' | 'zcash'
required
The UTXO chain.
Returns
string
The token contract address (nBTC or nZEC).
getUtxoConnectorConfig
Get the UTXO connector configuration from the contract.Signature
Parameters
'btc' | 'zcash'
required
The UTXO chain.
Returns
Promise
getUtxoAvailableOutputs
Get available UTXOs from the connector contract.Signature
Parameters
'btc' | 'zcash'
required
The UTXO chain.
Returns
Promise
Array of available UTXOs for withdrawal.
getUtxoTokenBalance
Get the nBTC/nZEC token balance for an account.Signature
Parameters
'btc' | 'zcash'
required
The UTXO chain.
string
required
NEAR account to check balance for.
Returns
Promise
Token balance in satoshis/zatoshis.
calculateUtxoWithdrawalFee
Calculate the bridge fee for a UTXO withdrawal.Signature
Parameters
'btc' | 'zcash'
required
The UTXO chain.
bigint
required
Withdrawal amount in satoshis/zatoshis.
Returns
Promise
Bridge fee amount.
Shim Functions
Functions to convert SDK transactions to library-specific formats.toNearKitTransaction
Convert aNearUnsignedTransaction to a near-kit TransactionBuilder. near-kit handles nonce, blockHash, and signing automatically.
Signature
Parameters
Near
required
A configured near-kit
Near instance.NearUnsignedTransaction
required
The unsigned transaction from the builder.
Returns
TransactionBuilder
A near-kit TransactionBuilder that can be sent with
.send() or built with .build().Example
toNearApiJsActions
ConvertNearUnsignedTransaction actions to @near-js/transactions Action array. Use this with Account.signAndSendTransaction().
Signature
Parameters
NearUnsignedTransaction
required
The unsigned transaction from the builder.
Returns
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
required
A
@near-js/accounts Account instance with signer configured.NearUnsignedTransaction
required
The unsigned transaction from the builder.
Returns
Promise
The transaction execution outcome.
Example
MPCSignature Class
Class representing an MPC signature from the NEAR bridge contract.Constructor
Properties
AffinePoint
The R component of the signature as an affine point.
Scalar
The S component of the signature.
number
The recovery ID (0 or 1).
Methods
toBytes
Convert the signature to bytes for use on Solana or EVM.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
TransferMessageForStorage
required
Returns
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.@zorsh/zorsh library and can be used for custom serialization: