Binance Smart Chain

Binance Smart Chain


Magic interacts with the Avalanche blockchain via Magic's extension NPM package @magic-ext/avalanche. The Avalanche extension also lets you interact with the blockchain using methods from Avalanche's Javascript SDK.


You can skip straight to our github example directly:

👉 Avalanche Example


01npm install --save @magic-ext/avalanche


01yarn add @magic-ext/avalanche

#Initializing Extension

Note: This is for X-Chain implementation. For generic EVM compatible C-Chain support refer to this documentation on configuring custom nodes.

#ES Modules/TypeScript

01import { Magic } from 'magic-sdk';
02import { AvalancheExtension } from '@magic-ext/avalanche';
04const magic = new Magic('YOUR API KEY', {
05  extensions: {
06    xchain: new AvalancheExtension({
07      rpcUrl: 'Avalanche node url',
08      chainId: 'Avalanche chain id',
09      networkId: 4, // Avalanche networkId
10    }),
11  },

#Send Transaction

#Getting Test AVAX

Before you can send transaction on the Avalanche blockchain, you'll need to acquire some test AVAX (Avalanche's native cryptocurrency for test network).

  1. Go to our Avalanche Example.
  2. Login with your email address
  3. Copy your Avalanche public address
  4. Go to the Avalanche Faucet
  5. Paste your copied Avalanche public address in the text input
  6. You can receive 10000000 nAVAX
  7. Now you can use your test AVAX in our example app

#Call Extension Method

Note that the Magic Avalanche extension follows the method names and conventions by Avalanche's Javascript SDK. To send a standard Avalanche blockchain transaction, you can call the magic.xchain.signTransaction() method.

#ES Modules/TypeScript

01import { Magic } from 'magic-sdk';
02import { AvalancheExtension } from '@magic-ext/avalanche';
03import { Avalanche, BinTools, Buffer, BN } from 'avalanche';
05const magic = new Magic('YOUR API KEY', {
06  extensions: {
07    xchain: new AvalancheExtension({
08      rpcUrl: 'Avalanche node url',
09      chainId: 'Avalanche chain id',
10      networkId: 4, // Avalanche networkId
11    }),
12  },
15const metadata = await magic.user.getMetadata();
16let myNetworkID = 4; //default is 3, we want to override that for our local network
17let myBlockchainID = 'X'; // The XChain blockchainID on this network
18let ava = new Avalanche('', 443, 'https', myNetworkID, myBlockchainID);
19let xchain = ava.XChain();
20let assetId = 'nznftJBicce1PfWQeNEVBmDyweZZ6zcM3p78z9Hy9Hhdhfaxm';
22let fromAddresses = [metadata.publicAddress];
23let toAddresses = ['X-everest1zr334udmau3xruusmwnyng3hug38errx83h6xq'];
24let sendAmount = 1000000;
26const signedTx = await magic.xchain.signTransaction(sendAmount, assetId, toAddresses, fromAddresses, toAddresses);
28console.log('signedTX', signedTx);
30let txid = await xchain.issueTx(signedTx);
32console.log('send transaction', txid);

Did you find what you were looking for?

Did you find what you were looking for?