Interacting With MLD-20 Tokens

Using a Front-End Application or Remix

Interacting with MLD-20 tokens, a standard on the MELD blockchain, can be done in various ways depending on your specific needs and technical background.

1. Interacting with MLD-20 Tokens in a Front-End Application

For those developing a front-end application, this typically involves using a web3 framework like Web3.js or Ethers.js, integrated with languages such as JavaScript or TypeScript. These frameworks allow you to connect your application to the MELD blockchain, enabling users to interact with MLD-20 tokens through a familiar web interface.

  • Install Web3.js: First, you'll need to install Web3.js in your project. It's a collection of libraries that allow you to interact with a local or remote ethereum node using HTTP, IPC, or WebSocket.

    npm install web3
  • Connecting to the MELD Blockchain:

    import Web3 from 'web3';
    
    const web3 = new Web3('https://testnet-rpc.meld.com/');
  • Interacting with an MLD-20 Token Contract:

    You'll need the ABI (Application Binary Interface) of the MLD-20 token contract and its address.

    const tokenAddress = 'YOUR_MLD20_TOKEN_ADDRESS';
    const tokenABI = [] // ABI of the MLD-20 token contract
    
    const tokenContract = new web3.eth.Contract(tokenABI, tokenAddress);
    
    // Example: Getting the total supply of the token
    tokenContract.methods.totalSupply().call()
      .then(totalSupply => console.log('Total Supply:', totalSupply));

2. Interacting with MLD-20 Tokens Using Remix

On the other hand, if you prefer a more direct approach, you can interact with these tokens through smart contract functions using platforms like Remix. Remix is a powerful web-based IDE that allows you to write, deploy, and interact with smart contracts directly on the blockchain. We'll be using the $MELD Token as an example here.

  1. Access Remix IDE: Open Remix IDE.

  2. Create a New File for the MELD Token Contract:

    • In the "File Explorers" tab, create a new folder by clicking the "Create New Folder" icon.

    • Name the folder contracts

    • Navigate inside the contracts folder and create a new file by clicking the "Create New Folder" icon.

    • Name the file MELDToken.sol.

  3. Paste the MELD Token Contract Code:

    • Copy the source code of the MELD Token contract. You can find the contract source code here.

    • Paste the copied code into the MELDToken.sol file you just created.

  4. Compile the Contract:

    • Go to the "Solidity Compiler" tab.

    • Select the appropriate compiler version (0.8.19).

    • Click "Compile MELDToken.sol".

  5. Connect to the MELD Mainnet:

    • Make sure your Web3 environment in Remix is connected to the MELD Mainnet. This might involve configuring a Web3 provider like MetaMask to connect to the MELD network.

  6. Load the Existing Contract:

    • Go to the "Deploy & Run Transactions" tab.

    • In the "Contract" dropdown, select 'MELD ERC20 - contracts/MELDToken.sol'.

    • Below that, paste the MELD Token address 0x333000333528b1e38884a5d1EF13615B0C17a301 into the "At Address" field.

    • Click "At Address" to load the existing contract.

  7. Interact with the Contract:

    • The functions of the MELD Token contract will now be displayed in the "Deployed Contracts" section.

    • You can interact with the contract's functions:

      • For instance, to check the total supply, click on the totalSupply() function.

      • To view the balance of a specific address, input the address into the balanceOf(address) function and execute it.

      • Similarly, you can execute other functions like transfer, approve, and allowance.

  8. Executing Functions:

    • Functions that read data (view and pure) can be queried without a transaction.

    • Functions that alter the state require a transaction. Be sure your connected account has the necessary permissions and funds.

Last updated