Skip to content

Commit

Permalink
Add rinkeby support, remove TRON from NFT Marketplace Listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Sramko committed Aug 20, 2021
1 parent 1278e4e commit 9721be2
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 100 deletions.
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,30 @@ $ npm run test
```

## Configuration and setup
Provide Tatum API key to process.env.TATUM_API_KEY variable. You can use dotenv or any other way.
There are modules and functions, that do not have to communicate with Tatum API, like wallet generation or signing of transactions locally.
In those cases, there is no need to provide TATUM_API_KEY parameter.

### Tatum API KEY

Provide Tatum API key to process.env.TATUM_API_KEY variable. You can use dotenv or any other way. There are modules and
functions, that do not have to communicate with Tatum API, like wallet generation or signing of transactions locally. In
those cases, there is no need to provide TATUM_API_KEY parameter.

```process.env.TATUM_API_KEY=${YOUR_API_KEY}```

There are some cases when requests fail to complete successfully. For instance, when you exceed request rate limitations.
To configure behavior when requests fails we provide env variables process.env.TATUM_RETRY_DELAY and process.env.TATUM_RETRIES.
### Testnet type

For Ethereum, there are 2 testnet chains supported - Ropsten (default one) and Rinkeby. To enable Rinkeby, you need to
set up TESTNET_TYPE parameter to rinkeby.

```process.env.TESTNET_TYPE=rinkeby```

### Retry Delay

There are some cases when requests fail to complete successfully. For instance, when you exceed request rate
limitations. To configure behavior when requests fails we provide env variables process.env.TATUM_RETRY_DELAY and
process.env.TATUM_RETRIES.

Variable process.env.TATUM_RETRY_DELAY specifies the number in milliseconds how long wait before the failed request is resent again.
Default value is 1000 milliseconds.
Variable process.env.TATUM_RETRY_DELAY specifies the number in milliseconds how long wait before the failed request is
resent again. Default value is 1000 milliseconds.

```process.env.TATUM_RETRY_DELAY=1000```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "1.21.6",
"version": "1.21.7",
"description": "Tatum API client allows browsers and Node.js clients to interact with Tatum API.",
"main": "dist/src/index.js",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
4 changes: 2 additions & 2 deletions src/connector/tatum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ axiosRetry(axios, {

const baseUrl = () => process.env.TATUM_API_URL || TATUM_API_URL;

const headers = () => ({ headers: { 'x-api-key': process.env.TATUM_API_KEY } })
const headers = () => ({headers: {'x-api-key': process.env.TATUM_API_KEY, 'x-testnet-type': process.env.TESTNET_TYPE || 'ethereum-ropsten'}});

export const get = async <T>(url: string): Promise<T> => {
const { data } = await axios.get(`${baseUrl()}${url}`, headers())
return data
}

// eslint-disable-next-line @typescript-eslint/ban-types
export const post = async <T extends object, U, V>(url: string, body?: U, classType?: ClassType<T>, header?: any): Promise<V> => {
export const post = async <T extends object, U, V>(url: string, body?: U, classType?: ClassType<T>): Promise<V> => {
await validateBody(body, classType);
const {data} = await axios.post(`${baseUrl()}${url}`, body, headers());
return data;
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/marketplace/listing.ts

Large diffs are not rendered by default.

45 changes: 44 additions & 1 deletion src/nft/marketplace/listing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CeloProvider} from '@celo-tools/celo-ethers-wrapper';
import {bscBroadcast, polygonBroadcast} from '../../blockchain';
import {bscBroadcast, polygonBroadcast, tronBroadcast} from '../../blockchain';
import * as listing from '../../contracts/marketplace';
import {
ApproveMarketplaceErc20Spending,
Expand Down Expand Up @@ -284,4 +284,47 @@ describe('Marketplace Listing tests', () => {
console.log(await polygonBroadcast(tx));
});
})
describe('Marketplace Listing TRON transactions', () => {
it('should deploy marketplace', async () => {
const test = await deployMarketplaceListing(true, {
'feeRecipient': 'TYMwiDu22V6XG3yk6W9cTVBz48okKLRczh',
'marketplaceFee': 250,
'chain': Currency.TRON,
'fromPrivateKey': '842E09EB40D8175979EFB0071B28163E11AED0F14BDD84090A4CEFB936EF5701',
'feeLimit': 500
});
console.log(test);
expect(test).toBeDefined();
});

it('should create listing native asset', async () => {
const txData = await prepareMarketplaceCreateListing(true, {
'contractAddress': 'TXseqo4U5yZZgVjjDzodA3par23pxevvtD',
'nftAddress': 'TGXh2YJhfwchMGKuzfEJ27W1VEJRKnMdy9',
'tokenId': '1',
'listingId': '1',
'isErc721': true,
'price': '0.001',
'seller': 'TYMwiDu22V6XG3yk6W9cTVBz48okKLRczh',
'chain': Currency.TRON,
'fromPrivateKey': '842E09EB40D8175979EFB0071B28163E11AED0F14BDD84090A4CEFB936EF5701',
'feeLimit': 100
});
expect(txData).toContain('txID');
console.log(await tronBroadcast(txData));
});

it('should buy listing native asset', async () => {
const txData = await prepareMarketplaceBuyListing(true, {
'contractAddress': 'TXseqo4U5yZZgVjjDzodA3par23pxevvtD',
'listingId': '1',
'amount': '0.002',
'chain': Currency.TRON,
'fromPrivateKey': '842E09EB40D8175979EFB0071B28163E11AED0F14BDD84090A4CEFB936EF5701',
'feeLimit': 100
});
expect(txData).toContain('txID');
console.log(await tronBroadcast(txData));
});
});
})
Loading

0 comments on commit 9721be2

Please sign in to comment.