Approving NFTs + NoRamp

noramp

NoRamp

Posted on November 8, 2022

Approving NFTs + NoRamp

NoRamp is a platform that allows developers, marketplaces and individual creators to perform buy and sell operations of NFTs through fiat. During the transaction, both parties will receive fiat instead of crypto which is why it's called "No"Ramp.

1: Creating a NoRamp Account

To create a NoRamp account you can look at our tutorial or you can go ahead and go to NoRamp and follow the steps.

2: Asset Approval

In order for us to use NoRamp as the transmitter of the asset through fiat money, we need to go through the process of asset approval.

It is vital for you to grant approval: Otherwise, NoRamp's objective might fail when transacting with the blockchain.

NFTs in NEAR and ETH have specific standards that allow granting permissions to wallet addresses such as EIP-721 or NEP-0178.

In this tutorial, you will be granting approvals programmatically with Javascript.

3: NoRamp's Wallet

In order to create a wallet in NoRamp so that we have the public key that we will granting approval for, you must go to NoRamp's wallet page and click on "Add Wallet"

Image description

In this step, you can import your own wallet or use NoRamp's managed wallet:

Image description

It is recommended to use NoRamp's managed since at the time of creating triggers, you won't have to worry about liquidity.

After creating the wallet, when you click on it, you will be able to see the public key. Something like this:

Image description

You will be using the public key (Account Id) in this tutorial referred as "NORAMP_WALLET_ADDRESS"

4: The Approvals + Javascript

Near

In the case of NEAR, we can use NEAR's sdk (Click Here for more information)

import * as nearAPI from "near-api-js";


const { keyStores, KeyPair } = nearAPI;
const myKeyStore = new keyStores.InMemoryKeyStore();
const PRIVATE_KEY = "YOUR_PRIVATE_KEY";
// creates a public / private key pair using the provided private key
const keyPair = KeyPair.fromString(PRIVATE_KEY);
// adds the keyPair you created to keyStore
await myKeyStore.setKey("testnet", "YOUR_ACCOUNT.testnet", keyPair);
Enter fullscreen mode Exit fullscreen mode

In the code above, we are:

  1. Importing a private key
  2. Creating the relationship between the private key and YOUR_ACCOUNT.testnet
  3. Saving the relation

It's important to note that if this is a production account, you must replace "testnet" with mainnet and the wallet address must contain "near". It would look like this:

await myKeyStore.setKey("mainnet", "YOUR_ACCOUNT.near", keyPair);
Enter fullscreen mode Exit fullscreen mode

Now, you can create an account variable containing the account:

const account = await nearConnection.account("YOUR_ACCOUNT.testnet");
Enter fullscreen mode Exit fullscreen mode

After doing the step above, we can create the contract instance which will allow to communicate with the smart contract (NFT smart contract in this case)

const contract = new Contract(
  account, // the account object that is connecting
  "YOUR_ACCOUNT.testnet",
  {
    // name of contract you're connecting to
    viewMethods: [""], // view methods do not change state but usually return a value
    changeMethods: ["nft_approve"], // change methods modify state (Change methods for NEP-0178)
  }
);
Enter fullscreen mode Exit fullscreen mode

Now, you can call the contract with the NFT approval

await contract. nft_approve(
  {
    token_id: "TOKEN_ID",
    account_id: "NORAMP_WALLET_ADDRESS"
  },
  "300000000000000", // attached GAS (optional)
  "1000000000000000000000000" // attached deposit in yoctoNEAR (optional)
);
Enter fullscreen mode Exit fullscreen mode

The final code would look like this: Click here to see Gist

ETH:

For this part, we will essentially execute the NFT approval in ethereum chain. Using ethers package (found here)

import {Contract, providers, Wallet, utils} from "ethers";

const provider = new providers.JsonRpcProvider({
   url: "http://127.0.0.1:8545",
});

const wallet = new Wallet("ETH_PRIVATE_KEY", provider);
Enter fullscreen mode Exit fullscreen mode

In the code above you are:
1) Creating a provider that communicates with the JSON RPC for the ETH chain. (Remember to put the URL of your preferred JSON RPC provider)
2) Creating a wallet object based on the ETH private key.

Now, you will create the contract object to execute the contract calls.

const contract = new Contract("CONTRACT_ID", ["function approve(address _approved, uint256 _tokenId)"], wallet);
Enter fullscreen mode Exit fullscreen mode

In the code above, we are creating the Contract instance. Any call to this instance will be paid under wallet.

Remember to replace CONTRACT_ID with your NFT contract.

const result = await (contract["approve"]("NORAMP_WALLET_ADDRESS", "TOKEN_ID", {
      gasPrice: "0",
      gasLimit: "1"
}));
Enter fullscreen mode Exit fullscreen mode

In the code above, you are calling approve function based on EIP-721 which has the following signature:

function approve(address _approved, uint256 _tokenId) external payable;
Enter fullscreen mode Exit fullscreen mode

which means we are passing two paremeters: NORAMP_WALLET_ADDRESS and TOKEN_ID.

In the case of gasPrice and gasLimit, you need to set the amounts to as required by the contract. This can vary.

6: Summary

1) We successfully created a NoRamp's managed wallet
2) We have successfully granted access NoRamp's to the NFT by calling the contract and granting the approval
3) We are ready to implement NoRamp's in our NFT marketplace

For NoRamp documentation: https://testnet.noramp.io/docs
For WebHook documentation: https://testnet.noramp.io/docs/api/webhooks
For further contact, you can reach out to: hello@noramp.io
We hope to see NoRamp powering your applications and developers.
Remember to follow us on Twitter @No_Ramp and stay tuned for upcoming and exciting developments.

💖 💪 🙅 🚩
noramp
NoRamp

Posted on November 8, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Approving NFTs + NoRamp
nft Approving NFTs + NoRamp

November 8, 2022