Secondary Sale - P2P sell and buy
Enabling users to sell items to other users
🔭 Guide Overview
In this guide you will use the Wallet SDK to create a sell order from one user and a buy order from another user and confirm that the sale happened. The exchange of the NFT vs NFT or ERC-20 token will happen in the same transaction thus ensuring that the seller is always compensated as much as they want and the buyer gets the exact token demanded. It allows you to create your own marketplace inside your platform where users exchange items and optionally give you a % of sale value for facilitating the sale.
Notice that we use the Wallet SDK to do this and not the APIs
We think that self-custody of NFT and other crypto assets is the future and we aim to build in such a way that enables your users to own their assets and for you to be free of managing user's keys. Thus, any actions on owned assets require the sign off of the user, instead of using x-api-key and APIs
The Croak Wallet SDK will be used to make buy and sell orders.
🏷️ Use-case Examples
- Users trading the rights to use a limited edition feature on your platform, eg. Traitsniper
- Users and NFT-investors exchanging digital collectibles of your platform
- Users trading NFTs that represent real world assets formalized and licensed by your platform
🧱 Implementation Steps
-
Client X-API-KEY : Get the client x-api-key to be used in the following steps. You can take a look at Create Client Guide ↗️ if you haven't already created the client.
-
Deploy contract : We need to first deploy a contract which will hold the ERC1155 tokens. Choose chain
mumbai
and typeOpenGlipERC1155
. We will support the others soon.
The above API with an example, see the API reference ↗️ for code snippet in lots of languages and more information about the API and the metadata (name, symbol, description...)> curl --request POST \ --url https://be.namasteapis.com/blockchain/v1/contract/create \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header 'x-api-key: TheCompanyAPIkey' \ --data ' { "name": "SomeName", "symbol": "SomeSymbol", "description": "SomeDescription", "chain": "mumbai", "image": "someimageurl.jpeg", "externalUrl": "someimageurl.jpeg", "type": "OpenGlipERC1155" } ' { "data": { "confirmed": true, "id": "62a38b9b08992327f2634b00", "name": "SomeName", "description": "SomeDescription", "chain": "mumbai", "image": "someimageurl.jpeg", "externalUrl": "someimageurl.jpeg", "media": [ { "type": "number", "value": "1" } ], "type": "OpenGlipERC1155", "contractAddress": "0xe9F3a256Beda25e4a30Cc65C61B108D74791A103", "transactionHash": "0x5e3bd8135074fd594582ed70878d1222e53dd9242e1ba60e4d14fe7da7611944", "deployer": "0xF1b6fceac6784a26360056973C41e0017DeE12e4", "factory": "0x0405aA9fef3986fd56470107D38f2a554E1856fa", "creatorId": "62335548760f50d618bc7b35", "owner": "0xF1b6fceac6784a26360056973C41e0017DeE12e4", }, "success": true, "message": "Contract created" }
You can try it yourself 😎 here!
- Create the Token Metadata : Use the id from the above as your
contractDataId
. In this case it is62a38b9b08992327f2634b00
. Create the token data using the following API, see API Reference ↗️ for more languages snippets and details on each field.
> curl --request POST \
--url https://be.namasteapis.com/blockchain/v1/token-data/create \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'x-api-key: TheCompanyAPIkey' \
--data '
{
"metadata": {
"name": "SomeName",
"description": "SomeDescription",
"image": "SomeImage.jpeg",
"external_url": "SomeWebsite.com",
"animation_url": "SomeVideo.mp4",
"attributes": "[]"
},
"supply": 1,
"assetContractId": "62a38b9b08992327f2634b00"
}
'
# Response
{
"data": {
"id": "62a38cb708992327f2634b36",
"creatorId": "62335548760f50d618bc7b35",
"type": "ERC1155_LAZY",
"name": "SomeName",
"description": "SomeDescription",
"externalUri": "SomeWebsite.com",
"imageUri": "SomeImage.jpeg",
"videoUri": "SomeVideo.mp4",
"attributes": "[]",
"supply": 1,
"reserveTokenDataId": "62a369c43a45893dcf7bae66",
"reserveTokenDataAmount": 10,
"assetContractId": "62a38b9b08992327f2634b00",
"tokenId": "50773715742106732018698306139051929138629421045594680327232414164177859221168",
},
"success": true,
"message": "Token data saved"
}
You can try it yourself 😎 here!
- Get the 2 wallets : Since this is P2P trade. We would need 2 wallets and make them trade with each other. Any 2 of your social accounts can be used (eg. gmail login) to create a non-custodial wallet using the Wallet SDK. You can follow the Guide to Create Wallet ↗️ to create the first wallet (the wallet gets created automatically when you login with gmail). Take care to use the same
x-api-key
as you are using in the Step 9 in that guide. Come back and resume this guide at this point.
Once you have recorded the first walletId
(assuming to be 627cb7ea2cd263018f2adfb7
for this example), you can log out using the following command in the Developer Console.
await glipAuthGlobal.logout();
Now go back to the Setup Wallet Guide ↗️ and start from Step 4 again but login with a different google account. Once the login is done save this walletId
which we will refer to further as the second walletId
(assuming to be 62de50119081671256277625
for this example)
- Send NFT to first wallet : Use the first
walletId
-627cb7ea2cd263018f2adfb7
and send thetokenDataId
-62a38cb708992327f2634b36
created in step 3. Use the airdrop api to send the token to the wallet id. See API Reference ↗️ for code snippets in more languages. You can also see more details about sending NFT to user wallet in the Send NFT to user's wallet guide ↗️
> curl --request POST \
--url https://be.namasteapis.com/blockchain/v1/airdrop/token-data \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'x-api-key: TheCompanyAPIkey' \
--data '
{
"destinations": [
"627cb7ea2cd263018f2adfb7"
],
"amounts": [
1
],
"tokenDataId": "62a38cb708992327f2634b36"
}
'
{
"data": [
{
"amount": 1,
"status": "success",
"cancelled": false,
"isClaimed": false,
"_id": "62a38d5108992327f2634b58",
"creatorId": "62335548760f50d618bc7b35",
"tokenDataId": "62a38cb708992327f2634b36",
"error": "",
"exchangeContract": "0x3B2A17fd2c4C3Bb968Efa91ae63AAfe8A7c5E69E",
"mintSaleType": "airdrop",
"minted": true,
"mintTxId": "0xef096055f6f59bead13bb247701b2af22ec86b3acf37e058c46c5683775d705b",
"mintTxStatus": "done",
"mintedAt": "2022-06-10T18:28:33.190Z",
"mintedPrice": "0",
"mintedCurrency": "USD",
"mintedTo": "0x8E8132a63EeD858CB8ABB3b7D0Bd3c4DF9E1B6bd",
"walletId": "627cb7ea2cd263018f2adfb7",
"id": "62a38d5108992327f2634b58"
}
],
"success": true,
"message": "Token minting started"
}
You can try it yourself 😎 here!
- Send ERC-20 tokens to second wallet : Now that you have sent one NFT to the first wallet, you need to send some ERC-20 tokens to second wallet to be able to make a trade.
Get the testERC20tokenDataIds
of your client. If you don't already have it saved go to Get Company API Reference ↗️ and get it for your client. Here we will assume - 62a369c43a45893dcf7bae66
is the tokenDataId of the ERC-20 token. Next use the following API to mint new ERC20 tokens to the second wallet. Here you will mint 100000 of this into the second walletId
- 62de50119081671256277625
> curl --request POST \
--url https://be.namasteapis.com/blockchain/v1/airdrop/test-fungible-token-data \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'x-api-key: TheCompanyAPIkey' \
--data '
{
"destinations": [
"627cb7ea2cd263018f2adfb7"
],
"amounts": [
100000
],
"tokenDataId": "62a369c43a45893dcf7bae66"
}
'
{
"data": [
{
"chainId": 80001,
"hash": "0x31898f611d9d31223258b7d8f68698f67448f686737dcaf69af050fda6ba3d2f",
"transactionId": "d0e33533-0ff2-4b8e-b670-640553ce4039",
"value": "0x0",
"gasPrice": 30000000000,
"gasLimit": 2500000,
"to": "0x5d38889BFcB2610ab7387c5AC3aC7b56265fc93A",
"from": "0x923dacd378daae95d4ba88aae08d598609acf0b6",
"data": "0x40c10f190000000000000000000000008e8132a63eed858cb8abb3b7d0bd3c4df9e1b6bd00000000000000000000000000000000000000000000000000000000000186a0",
"nonce": 134,
"status": "sent",
"speed": "fast",
"validUntil": "2022-06-11T02:33:07.261Z",
"createdAt": "2022-06-10T18:33:08.182Z",
"sentAt": "2022-06-10T18:33:08.182Z",
"pricedAt": "2022-06-10T18:33:08.182Z"
}
],
"success": true,
"message": "Token minting started"
}
You can try it yourself 😎 here!
- Create sell order from first wallet : Now you are all set to make the marketplace orders. Go to localhost:8080 and log out of the second wallet (assuming you left it there after Step 4). Log back in with the first social account to gain access to the first wallet. You will have to create a sell order from this wallet as the owner of the NFT. No other wallet will be able to do this action. Notice that the sell order in Secondary Sale is coming from the Wallet SDK on the front-end and not the backend/serverless service which is the case in Step 4 of Primary Sale Guide ↗️ as it requires the
x-api-key
which is supposed to be kept private.
Go to the Developer Console after logging in with the first social account and use the auto-suggestion got see the parameters of the sell request.
Here makeToken
is what the wallet is offering to sell and takeToken
is what is required in return which will be the ERC-20 coin. So makeTokenDataId
is the tokenDataId
created in Step 3 here - 62a38cb708992327f2634b36
. makeAmount
will be 1 as it is an NFT. takeTokeDataId
is the tokenDataId
of the ERC-20 coin which is used in Step 5 here - 62a369c43a45893dcf7bae66
and the takeAmount
is, say, 1000, just because you're feeling a little lucky today. You can put the following command in the console
await glipAuthGlobal.sellNFT(
"62a38cb708992327f2634b36", 1,
"62a369c43a45893dcf7bae66", 1000);
This will return an id
which you should save as the Sell Order Id which will be used for creating the buy order.
- Create buy order from second wallet : The buy order will be created by the second wallet. So log out using the same command in the console and login with the second wallet. You can see the function parameters for creating the buy order in the developer console.
Updated almost 3 years ago