Fiat on-ramp not working

I installed fiat on-ramp plugin properly and added api key: as per screenshot below

My fiat on ramp implementation code below:

whats wrong?

<!DOCTYPE html>
<html>
  <head>
    <title>TaxToken</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
    <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
  </head>

  <body>
    <h1>Buy</h1>

    <button onclick="buyCrypto()" id="btn-buy">Buy Crypto</button>


    <script type="text/javascript">

    const serverUrl = "https://ynriprd0e4nd.usemoralis.com:2053/server";
    const appId = "vOQwWdGZJbTlt9m9VFMijeSnTvZWTeLuS8a2T6Dd";
    Moralis.start({ serverUrl, appId });

    //Moralis.initialize("vOQwWdGZJbTlt9m9VFMijeSnTvZWTeLuS8a2T6Dd");
    //Moralis.serverURL= "vOQwWdGZJbTlt9m9VFMijeSnTvZWTeLuS8a2T6Dd";
    
    //Moralis.initPlugins();
    //Moralis.Plugins.fiat.buy();

    (async function(){
     Moralis.initPlugins();
    })();
    
    function buyCrypto(){
     console.log('buy crypto');
     Moralis.Plugins.fiat.buy();
    }
    </script>
  </body>
</html>

if i execute Moralis.Plugins.fiat.buy(); this line in the console i get the following output:


Promise { <state>: "pending" }
​
<state>: "fulfilled"
​
<value>: Object { data: "https://widget.onramper.com?color=1d2d50&apiKey=pk_test_ass3gtLSWQpI11IWUZLJdrfyQhj7bTw_3xwLvhEvH6Q0", triggers: (1) […] }
1 Like

it looks like it works if you use an iframe:

    <iframe id="myIframe" src="" width = "350" height="650" style ="display:none"></iframe> <br>
    ...

     async function iframefiat(){
      let result = await Moralis.Plugins.fiat.buy( undefined, {disableTriggers: true});
      document.getElementById("myIframe").style.display = "block";
      document.getElementById("myIframe").src = result.data;
     }

Hey @mostain

Please update the plugin to the latest version in order to solve the issue.

async function buyCrypto() {
        await Moralis.start({ serverUrl, appId });
        Moralis.initPlugins();
        await Moralis.Plugins.fiat.buy({ newTab: true });
}

thank you, can tell which is the latest version?

@dani Thank you very much for your kind info, Unfortunately it did not resolve my issue, i am using firefox is there any problem with firefox?

iframefiat function working but buyCrypto does not.

here is my full code. is there anything missing?

<!DOCTYPE html>
<html>
  <head>
    <title>TaxToken</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
    <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
  </head>

  <body>
    <h1>Buy</h1>

    <button onclick="buyCrypto()" id="btn-buy">Buy Crypto</button>  <br>

    <iframe id="myIframe" src="" width="350" height="650" style="display:none"></iframe>


    <script type="text/javascript">

    const serverUrl = "https://ynriprd0e4nd.usemoralis.com:2053/server";
    const appId = "vOQwWdGZJbTlt9m9VFMijeSnTvZWTeLuS8a2T6Dd";
    //Moralis.start({ serverUrl, appId });

    {{/* (async function(){
     Moralis.initPlugins();
    })(); */}}


    async function buyCrypto() {
            await Moralis.start({ serverUrl, appId });
            Moralis.initPlugins();
            await Moralis.Plugins.fiat.buy({ newTab: true });
    }

    async function iframefiat(){
        let result = await Moralis.Plugins.fiat.buy(undefined, {disableTriggers: true});
        document.getElementById('myIframe').style.display='block';
        document.getElementById('myIframe').src= result.data;
    }
    </script>
  </body>
</html>

run this

<!DOCTYPE html>
<html>
  <head>
    <title>TaxToken</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
    <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
  </head>

  <body>
    <h1>Buy</h1>

    <button onclick="buyCrypto()" id="btn-buy">Buy Crypto</button>

    <script type="text/javascript">
      const serverUrl = 'https://psvgohe33tol.usemoralis.com:2053/server';
      const appId = 'FNRaaWWRzn2dp8ItQBvPhNlc4D4iLVP0ng17BXdR';

      async function buyCrypto() {
        await Moralis.start({ serverUrl, appId });
        Moralis.initPlugins();
        await Moralis.Plugins.fiat.buy({newTab: true});
      }
    </script>
  </body>
</html>

I tried your server details and is not working

 const serverUrl = "https://ynriprd0e4nd.usemoralis.com:2053/server";
    const appId = "vOQwWdGZJbTlt9m9VFMijeSnTvZWTeLuS8a2T6Dd";

Have you updated the plugin?

@dani wow superb your code works on my system with firefox without any issue except the popup blocks. so whats wrong with my appid and serverurl.

@dani as your code works, i just replace your serverUrl and appID to my one and it does not work again, that means the problem with my plugin or apiToken, am i right?

You did not update the plugin probably. Which version do you have installed?

@dani Fiat Plugin -> https://moralis.io/plugins/fiat by Moralis v0.0.19

The latest version is 0.0.20
You have to update the plugin

1 Like

@dani yes i am doing it now. Thank you very much dani, I am a golang developer, if you need any assistance regarding hardware based programming or anything you may count me in.

1 Like