I m trying to make a dapp that takes eth as payment. How can i do that in nextjs ? I couldn’t find it in documentation. Thanks in advice.
what part you don’t know how to do? asking because it could be complex depending on the used approach
Here is my code:
import Moralis from 'moralis';
const { EvmChain, EvmTransaction } = require("@moralisweb3/evm-utils");
const Moralis_ = require("moralis-v1/node");
export async function buy(address){
await Moralis.start({ apiKey: process.env.MORALIS_API_KEY});
const chain = EvmChain.ROPSTEN;
const nativeBalance = await Moralis.EvmApi.account.getNativeBalance({
address, chain
});
const options = {
type: "native",
amount: Moralis_.Units.ETH("0.5"),
receiver: "0x..",
};
let result = await Moralis_.transfer(options);
console.log(result);
}
export default buy;
implemantation link is here https://v1docs.moralis.io/moralis-dapp/sending-assets/transfer-eth
transfer doesn’t work now with moralis v2 sdk or with v1, you will have to use web3/ethers directly to make that transfer, you will also need a RPC node url
Thanks a lot one more question, same thing is true for server functions ?, can i use the server functions such as creating objects to save the database and querying on the data?
with version 1 of moralis sdk, when you specify a server, you should be able to connect to the database for that particular server
with version 2 of moralis sdk you can not do that as you will not connect to the server and you will only use an API key
Actually I have an api key, can I use the server functionalities ?
you can look at this tutorial on how to use nextJs with moralis v2 sdk:
with nextJs you can save the data locally on your server if you want
thanks a lot that is enough, in server side i will use php, and web3/ethers. that is the best way i think thanks.