multichain.js
v1.0.3
Published
Control accounts across multiple chains with NEAR Protocol
Downloads
27
Maintainers
Readme
Multichain.js
multichain.js is a TypeScript library that allows you to control accounts on multiple chains
from a single NEAR Account
Installation
yarn add multichain.jsUsage
import { Account } from '@near-js/accounts'
import { KeyPair } from '@near-js/crypto'
import { JsonRpcProvider } from '@near-js/providers'
import { KeyPairSigner } from '@near-js/signers'
import { getAdapter, chains } from 'multichain.js'
async function main() {
// NEAR Account
const provider = new JsonRpcProvider({ url: 'https://test.rpc.fastnear.com' })
const nearAccountId = 'your-account.near'
const signer = new KeyPairSigner(KeyPair.fromString('ed25519:...'))
const account = new Account(nearAccountId, provider, signer)
// Ethereum Adapter
const adapter = getAdapter({ chain: chains.ARBITRUM })
const { address } = await adapter.getControlledAccount({ nearAccountId })
const balance = await adapter.getBalance({ address })
const txHash = await adapter.transfer({
to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
amount: '10000000000000000', // 0.01 ETH
nearAccount: account,
})
console.log('Address:', address)
console.log('Balance:', balance)
console.log('Transaction:', tx)
}
main()If you want to use a testnet NEAR account be sure to add the mpcNetwork: testnet parameter to getAdapter
const adapter = getAdapter({ chain: chains.ARBITRUM, mpcNetwork: 'testnet' })You can control multiple accounts on each chain, for that you only need to change the addressIndex (defaults to 0)
on both getControlledAccount and transfer
const { address } = await adapter.getControlledAccount({ nearAccountId, addressIndex: 1 })
const txHash = await adapter.transfer({
to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
amount: '10000000000000000', // 0.01 ETH
nearAccount: account,
addressIndex: 1
})Supported Chains
The library provides chain adapters for the following blockchain networks:
- EVM Chains: Ethereum, BSC, Polygon, Arbitrum, Optimism, and other EVM-compatible networks
Each chain adapter provides a unified interface for:
- Check balance of native and fungible tokens
- Transfer native and fungible tokens
