Connect to Avalanche Node
Fast and Reliable Full Nodes and Archive Full Nodes for Avalanche!
Need a fast and reliable full node, but already have your own backend? Then Moralis Speedy Nodes are for you! Get direct WebSocket and JSON RPC access to Moralis full nodes and archive full nodes. Sign up for a free account at moralis.io to get started!

Get Your Avalanche C-Chain Node URL

Once you log into your account, go to the "Speedy Nodes" section. Click on the "Endpoints" button for the Avalanche Network. You will see separate URLs for each network and each archive version.

JSON RPC

Click on the "HTTP" tab and copy the link for the mainnet (or your desired environment). It will look something like this:
1
https://speedy-nodes-nyc.moralis.io/1a2b3c4d5e6f1a2b3c4d5e6f/avalanche/mainnet
Copied!

WebSockets

Click on the "WS" tab and copy the link for your desired network.
1
wss://speedy-nodes-nyc.moralis.io/1a2b3c4d5e6f1a2b3c4d5e6f/avalanche/mainnet/ws
Copied!

Connect to Your Speedy Node

With your Speedy Node URL in hand, it's time to put it to use!

Web3 JS

First import the web3.js library.
1
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
Copied!
Or via npm then import.
1
npm install web3
Copied!
1
const Web3 = require('web3');
Copied!
Now that the library is imported, a provider can be created.
1
const NODE_URL = "YOUR SPEEDY NODE URL HERE";
2
const provider = new Web3.providers.HttpProvider(NODE_URL);
3
const web3 = new Web3(provider);
Copied!
That's it! See the web3.js docs for more details on how to use the web3 object.

Ethers JS

First import the ethers.js library.
1
<script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"
2
type="application/javascript"></script>
Copied!
Or via npm, then import it in the browser or in NodeJS.
1
npm install ethers
Copied!
1
// JavaScript, NodeJS
2
const { ethers } = require("ethers");
3
​
4
// ES6 or typescript
5
import { ethers } from "ethers";
Copied!

JSON RPC

Next, create a provider and if needed a signer to sign transactions.
1
const NODE_URL = "YOUR SPEEDY NODE URL HERE";
2
const provider = new ethers.providers.JsonRpcProvider(NODE_URL);
3
​
4
// provider is read-only get a signer for on-chain transactions
5
const signer = provider.getSigner();
Copied!

WebSockets

1
const NODE_URL = "YOUR SPEEDY NODE URL HERE";
2
const provider = new ethers.providers.WebSocketProvider(NODE_URL);
3
​
4
// provider is read-only get a signer for on-chain transactions
5
const signer = provider.getSigner();
Copied!
And there you have it! See the ethers.js docs for more details on how to use providers and signers.
Last modified 28d ago