All pages
Powered by GitBook
1 of 1

Usage examples

Below are some examples demonstrating how to make requests to each of the API methods described earlier.

1. Prepare a Transaction

These examples use the requests library, which is a popular choice for making HTTP requests in Python. If you haven't already, you will need to install the requests library using pip:

pip install requests
import requests
import json

url = "https://api.mama.io/v1/reforge/prepareReforge"
headers = {"Content-Type": "application/json"}
data = {
    "sourceAmount": "100",
    "sourceToken": "0x3c6af76181891a6f0f438d4d0fc1474f0e8ca9a0",
    "destinationToken": "0xc61e8563d354c4870d3526361d8531d79cd5dfe3",
    "destinationChainId": "0x61"
}

response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.text)

To use axios for making HTTP requests in JavaScript, you first need to ensure that axios is installed in your project. If you haven't installed it yet, you can do so by running:

npm install axios
const axios = require('axios');

const url = "https://api.mama.io/v1/reforge/prepareReforge";
const headers = {
  "Content-Type": "application/json"
};
const data = {
  "sourceAmount": "100",
  "sourceToken": "0x3c6af76181891a6f0f438d4d0fc1474f0e8ca9a0",
  "destinationToken": "0xc61e8563d354c4870d3526361d8531d79cd5dfe3",
  "destinationChainId": "0x61"
};

axios.post(url, data, { headers: headers })
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error('Error:', error.response.data);
  });

2. Execute a Transaction Asynchronously

url = "https://api.mama.io/v1/reforge/executeReforgeAsync"
data = {
    "tx": "prepared_transaction_data",
    "walletData": {
        "rpcUrl": "https://sourcechain.rpc.url",
        "privateKey": "your_wallet_private_key"
    }
}

response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.text)
const axios = require('axios');

const url = "https://api.mama.io/v1/reforge/executeReforgeAsync";
const headers = {
  "Content-Type": "application/json"
};
const data = {
  "walletData": {
    "rpcUrl": "https://sourcechain.rpc.url",
    "privateKey": "your_wallet_private_key"
  }
};

axios.post(url, data, { headers })
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.data : error.message);
  });

3. Execute a Transaction

url = "https://api.mama.io/v1/reforge/executeReforge"
data = {
    "tx": "prepared_transaction_data",
    "walletData": {
        "rpcUrl": "https://sourcechain.rpc.url",
        "privateKey": "your_wallet_private_key"
    }
}

response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.text)
const axios = require('axios');

const url = "https://api.mama.io/v1/reforge/executeReforge";
const headers = {
  "Content-Type": "application/json"
};
const data = {
  "walletData": {
    "rpcUrl": "https://sourcechain.rpc.url",
    "privateKey": "your_wallet_private_key"
  }
};

axios.post(url, data, { headers })
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.data : error.message);
  });

4. Get Supported Chains and Tokens

url = "https://api.mama.io/v1/reforge/getChainsAndTokens"

response = requests.get(url)
print(response.text)
const axios = require('axios');

const url = "https://api.mama.io/v1/reforge/getChainsAndTokens";

axios.get(url)
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.data : error.message);
  });

These examples show how to use different languages to interact with the API, including how to send GET and POST requests, how to include headers, and how to serialize to JSON for the request body. Remember to adjust parameters as needed to match your requirements.