Skip to main content

Installation

To interact with the EVM network, you will need to use a web3 provider library, such as ethers.js, with Magic. ⁠To get started, install the following dependencies for your project:

Ethers.js

Initialization

The Magic class is the entry-point to the Magic SDK. It must be instantiated with a Magic publishable key.
ImportantEthereum provider is only supported in [email protected] or later versions.

Ethers.js

ES Modules/TypeScript
CommonJS

Mainnet

Mainnet Block Explorer: https://etherscan.io
JavaScript

Testnet

Sepolia Block Explorer: https://sepolia.etherscan.io/ Sepolia Testnet Faucet: https://sepoliafaucet.com/
JavaScript

Custom Node

You can allow specific URLs to interact with the Magic SDK, such as a custom RPC URL to send transactions to your node. The Content Security Policy (CSP) of a browser dictates what resources can be loaded. You can update the policy in the settings page of the dashboard with your custom URL.
ImportantThe use of a custom node will require the RPC URL to the project’s Content Security Policy from your Magic Dashboard. Refer to the CSP documentation.
JavaScript

Common Methods

NoteAll Web.js examples are using [email protected] or later version.

Send Transaction

Ethers.js

Sign Message

Ethers.js

Personal Sign

Sign Typed Data v1

Sign Typed Data v3

Sign Typed Data v4

Get Balance

Ethers.js

Smart Contract

In this example, we’ll be demonstrating how to use Magic with ethers.js to interact with Solidity smart contracts. The simple Hello World contract allows anyone to read and write a message to it.
Solidity

Deploy Contract

Ethers.js

Read From Contract

Ethers.js

Write to Contract

Ethers.js

Resources