Sup guys?!
Iām using Magic Link to authenticate. But how do I change the network to BSC(mainnet)? Is it the same way like the other login methods by specifying network: "bsc"
or something else⦠Because other login methods have chain:
parameter and Magic Link has network:
parameter! So I wonder asigning "bsc"
to network:
will work or not! Need some clarification here please!
here you must specify the netwrok ID. for bsc this is 56. consider below an example given in th docs which is connecting to opimism
const customNodeOptions = {
rpcUrl: 'https://kovan.optimism.io',
chainId: 69
}
// Setting network to Optimism Testnet
export const magicOptimism = new Magic(process.env.REACT_APP_MAGIC_PUBLISHABLE_KEY, { network: customNodeOptions });
although i believe the chainID alone should be enough also. but yes to awnser your question you need to use the chain ID as the network and not a string of the chain name as you have
Thanks it worked for BSC!
Iām also using Magic Link to authenticate users, through the Moralis integration. It works great! Hereās my code, with the network specified as ārinkebyā plus error handling. It works fine using the Moralis.authenticate with options set.
const magicWalletHandler = async () => {
await authenticate({
provider: "magicLink",
email: formData.email,
apiKey: "pk_XXXXXXXXXXXXXXXX",
network: "rinkeby",
})
.then(function (user) {
console.log("logged in user:", user);
console.log(user.get("ethAddress"));
})
.catch(function (error) {
console.log(error);
});
};
The open question I have is about the user changing networks. If the user authenticates through Moralis.authenticate with the magicLink provider, and then the user changes networks, do they have to login all over again with Magic Link?
If thereās no option to change the chain within the Magic interface then youāll have to re-authenticate.
I reached out to Magic to find out. Iām also reaching out to Web3Auth because their tor.us wallet has the ability to change chains, but I still canāt find it in the documentation for custom auth.
Itās hard enough to get novice users to try the product, so I donāt want to overwhelm them at onboarding by making them choose a chain!
What chain are the contracts deployed on that users will be interacting with in your app? That probably should be your default chain for Magic.
Magic DOES support changing chains without having to reauthenticate, and the public address is the same when you change chains. They provide a demo here:
The question is wether it is possible to pass the full node options to Magic through the Moralis integration, like when you work with Magic directly:
import { Magic } from 'magic-sdk';
import Web3 from 'web3';
/**
* Configure Polygon Connection
*/
const polygonNodeOptions = {
rpcUrl: 'https://rpc-mumbai.maticvigil.com/',
chainId: 80001,
};
export const magicMatic = new Magic(
process.env.REACT_APP_MAGIC_PUBLISHABLE_KEY,
{ network: polygonNodeOptions }
);
magicMatic.network = 'matic';
export const maticWeb3 = new Web3(magicMatic.rpcProvider);
/**
* Configure Ropsten Connection
*/
const ropstenNodeOptions = {
rpcUrl: process.env.REACT_APP_ROPSTEN_RPC,
chainId: 3,
};
export const magicEthereum = new Magic(
process.env.REACT_APP_MAGIC_PUBLISHABLE_KEY,
{ network: ropstenNodeOptions }
);
magicEthereum.network = 'ethereum';
export const ethWeb3 = new Web3(magicEthereum.rpcProvider);
The question is wether it is possible to pass the full node options to Magic through the Moralis integration, like when you work with Magic directly:
You can look at the Magic connector to see how this could be integrated.
Yeah currently no switchNetwork
in the magic link Moralis integration. Alternatively, customization with Moralis is possible for any EIP1193 provider. Since MagicLink already has itās connector in our SDK, I believe you can simply extend it to create a new MagicLink custom connector that includes a switchNetwork functionality within the MagicLink connector class