Skip to content

Commit

Permalink
Add missing examples - evm (#331)
Browse files Browse the repository at this point in the history
* Add missing examples - celo

* Add missing examples - eth

* Add missing examples - bsc

* Add missing examples - kcs

* Add missing examples - one

* Add missing examples - polygon

* Tweaks

* Lint
  • Loading branch information
jakcinmarina authored Jan 27, 2022
1 parent 33ee7fb commit 668b94d
Show file tree
Hide file tree
Showing 45 changed files with 2,389 additions and 9 deletions.
75 changes: 75 additions & 0 deletions examples/bsc-example/src/app/bsc.api.example.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,83 @@
import { TransferBscBlockchain } from '@tatumio/api-client'
import { TatumBscSDK } from '@tatumio/bsc'
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'

const bscSDK = TatumBscSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function bscApiExample() {
const contractTransactionHash = await bscSDK.api.bscBlockchainSmartContractInvocation({
contractAddress: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85',
methodName: 'transfer',
methodABI: {
input: [
{
internalType: 'uint256',
name: 'amount',
type: 'uint256',
},
],
name: 'stake',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
params: ['0x632'],
})

const web3 = await bscSDK.api.bscWeb3Driver('asdlkfjnqunalkwjfnq2oi303294857k', {
jsonrpc: '2.0',
method: 'web3_clientVersion',
params: [],
id: 2,
})

const transferHash = await bscSDK.api.bscBlockchainTransfer({
data: 'My note to recipient.',
nonce: 0,
to: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85',
// TODO openapi bug
currency: TransferBscBlockchain.currency.B2U_BSC,
fee: {
gasLimit: '40000',
gasPrice: '20',
},
amount: '100000',
fromPrivateKey: '0x05e150c73f1920ec14caa1e0b6aa09940899678051a78542840c2668ce5080c2',
})

const broadcastHash = await bscSDK.api.bscBroadcast({
txData: '62BD544D1B9031EFC330A3E855CC3A0D51CA5131455C1AB3BCAC6D243F65460D',
signatureId: '1f7f7c0c-3906-4aa1-9dfe-4b67c43918f6',
})

const gasInfo = await bscSDK.api.bscEstimateGas({
from: '0xfb99f8ae9b70a0c8cd96ae665bbaf85a7e01a2ef',
to: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85',
amount: '100000',
data: 'My note to recipient.',
})

const privateKey = await bscSDK.api.bscGenerateAddressPrivateKey({
index: 0,
mnemonic: 'urge pulp usage sister evidence arrest palm math please chief egg abuse',
})

const address = await bscSDK.api.bscGenerateAddress(
'xpub6EsCk1uU6cJzqvP9CdsTiJwT2rF748YkPnhv5Qo8q44DG7nn2vbyt48YRsNSUYS44jFCW9gwvD9kLQu9AuqXpTpM1c5hgg9PsuBLdeNncid',
1,
)
const wallet = await bscSDK.api.bscGenerateWallet(
'urge pulp usage sister evidence arrest palm math please chief egg abuse',
)
const balance = await bscSDK.api.bscGetBalance('0x3223AEB8404C7525FcAA6C512f91e287AE9FfE7B')
const block = await bscSDK.api.bscGetBlock(
'0x5d40698ee1b1ec589035f2a39c6162287e9056868cc79d66cfb248ba9f66c3fc',
)
const currentBlock = await bscSDK.api.bscGetCurrentBlock()
const transaction = await bscSDK.api.bscGetTransaction(
'0xe6e7340394958674cdf8606936d292f565e4ecc476aaa8b258ec8a141f7c75d7',
)
const transactionCount = await bscSDK.api.bscGetTransactionCount(
'0xdac17f958d2ee523a2206206994597c13d831ec7',
)
}
22 changes: 22 additions & 0 deletions examples/bsc-example/src/app/bsc.blockchain.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,29 @@ import { TatumBscSDK } from '@tatumio/bsc'
const bscSDK = TatumBscSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function bscBlockchainExample() {
const broadcastHash = await bscSDK.blockchain.broadcast({
txData: '62BD544D1B9031EFC330A3E855CC3A0D51CA5131455C1AB3BCAC6D243F65460D',
signatureId: '1f7f7c0c-3906-4aa1-9dfe-4b67c43918f6',
})

const gasInfo = await bscSDK.blockchain.estimateGas({
from: '0xfb99f8ae9b70a0c8cd96ae665bbaf85a7e01a2ef',
to: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85',
amount: '100000',
data: 'My note to recipient.',
})

const transaction = await bscSDK.blockchain.get(
'0xe6e7340394958674cdf8606936d292f565e4ecc476aaa8b258ec8a141f7c75d7',
)
const balance = await bscSDK.blockchain.getBlockchainAccountBalance(
'0x3223AEB8404C7525FcAA6C512f91e287AE9FfE7B',
)
const block = await bscSDK.blockchain.getBlock(
'0x305c58c8c62399097f1ea702e337f13be6b3a3ed28867d530d8a03191f040b9c',
)
const currentBlock = await bscSDK.blockchain.getCurrentBlock()
const transactionsCount = await bscSDK.blockchain.getTransactionsCount(
'0x3223AEB8404C7525FcAA6C512f91e287AE9FfE7B',
)
}
174 changes: 174 additions & 0 deletions examples/bsc-example/src/app/bsc.ledger.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import { CreateTrade, VirtualCurrency } from '@tatumio/api-client'
import { TatumBscSDK } from '@tatumio/bsc'
import { Currency } from '@tatumio/shared-core'
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'

const bscSDK = TatumBscSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function bscLedgerAccountExample() {
const account = await bscSDK.ledger.account.create({
currency: Currency.BSC,
})
const accounts = await bscSDK.ledger.account.createMultiple({
accounts: [{ currency: Currency.BSC }, { currency: Currency.BSC }],
})
await bscSDK.ledger.account.activate('5e68c66581f2ee32bc354087')
await bscSDK.ledger.account.deactivate('5e68c66581f2ee32bc354087')
await bscSDK.ledger.account.freeze('5e68c66581f2ee32bc354087')
await bscSDK.ledger.account.unfreeze('5e68c66581f2ee32bc354087')
await bscSDK.ledger.account.update('5e68c66581f2ee32bc354087', {
accountCode: 'AC_1011_B',
accountNumber: '123456',
})

const accountById = await bscSDK.ledger.account.get('5e68c66581f2ee32bc354087')
const allAccounts = await bscSDK.ledger.account.getAll(10)
const balance = await bscSDK.ledger.account.getBalance('5e68c66581f2ee32bc354087')
const blockedAmounts = await bscSDK.ledger.account.getBlockedAmountsByAccountId('5e68c66581f2ee32bc354087')
const customerAccounts = await bscSDK.ledger.account.getByCustomerId(10, '5e6be89ee6aa436299950c3f')
}

export async function bscLedgerBlockAmountExample() {
const accountId = await bscSDK.ledger.blockAmount.block('5e6be89ee6aa436299950c3f', {
amount: '5',
type: 'DEBIT_CARD_OP',
description: 'Card payment in the shop.',
})

const txResult = await bscSDK.ledger.blockAmount.unblockWithTransaction('5e6be89ee6aa436299950c3f', {
recipientAccountId: '5e6645712b55823de7ea82f2',
amount: '5',
anonymous: false,
compliant: false,
transactionCode: '1_01_EXTERNAL_CODE',
paymentId: '9625',
recipientNote: 'Private note',
baseRate: 1,
senderNote: 'Sender note',
})

await bscSDK.ledger.blockAmount.unblock('5e6be89ee6aa436299950c3f')
}

export async function bscLedgerCustomerExample() {
await bscSDK.ledger.customer.activate('5e68c66581f2ee32bc354087')
await bscSDK.ledger.customer.deactivate('5e68c66581f2ee32bc354087')
await bscSDK.ledger.customer.disable('5e68c66581f2ee32bc354087')
await bscSDK.ledger.customer.enable('5e68c66581f2ee32bc354087')
const customer = await bscSDK.ledger.customer.get('5e68c66581f2ee32bc354087')
const customers = await bscSDK.ledger.customer.getAll(10)
const updatedCustomer = await bscSDK.ledger.customer.update('5e68c66581f2ee32bc354087', {
externalId: '123654',
})
}

export async function bscLedgerOrderBookExample() {
await bscSDK.ledger.orderBook.cancel('7c21ed165e294db78b95f0f1')
await bscSDK.ledger.orderBook.cancelByAccount('5e68c66581f2ee32bc354087')
const newTrade = await bscSDK.ledger.orderBook.newTrade({
// TODO openapi bug
type: CreateTrade.type.BUY,
price: '8650.4',
amount: '15000',
pair: 'BSC/EUR',
currency1AccountId: '7c21ed165e294db78b95f0f1',
currency2AccountId: '7c21ed165e294db78b95f0f1',
feeAccountId: '7c21ed165e294db78b95f0f1',
fee: 1.5,
attr: {
sealDate: 1572031674384,
percentBlock: 1.5,
percentPenalty: 1.5,
},
})
const trade = await bscSDK.ledger.orderBook.get('7c21ed165e294db78b95f0f1')
const activeBuyTrades = await bscSDK.ledger.orderBook.getActiveBuyTrades({
id: '7c21ed165e294db78b95f0f1',
customerId: '5e68c66581f2ee32bc354087',
pageSize: 10,
})

const activeSellTrades = await bscSDK.ledger.orderBook.getActiveSellTrades({
id: '7c21ed165e294db78b95f0f1',
customerId: '5e68c66581f2ee32bc354087',
pageSize: 10,
})

const historicalTrades = await bscSDK.ledger.orderBook.getHistorical({
id: '7c21ed165e294db78b95f0f1',
customerId: '5e68c66581f2ee32bc354087',
pageSize: 10,
})
}

export async function bscLedgerTransactionExample() {
const transactionCount = await bscSDK.ledger.transaction.countByAccount({
id: '5e6be8e9e6aa436299950c41',
})
const transactionByCustomerCount = await bscSDK.ledger.transaction.countByCustomer({
id: '5e6be8e9e6aa436299950c41',
})
const transactions = await bscSDK.ledger.transaction.getAll({})
const transactionByAccount = await bscSDK.ledger.transaction.getAllByAccount({
id: '5e6645712b55823de7ea82f1',
})
const transactionByCustomer = await bscSDK.ledger.transaction.getAllByCustomer({
id: '5e6be8e9e6aa436299950c41',
})
const transactionByReference = await bscSDK.ledger.transaction.getAllByReference('5e6be8e9e6aa436299950c41')
const transactionResult = await bscSDK.ledger.transaction.send({
senderAccountId: '5e6645712b55823de7ea82f1',
recipientAccountId: '5e6645712b55823de7ea82f2',
amount: '5',
})
const batchTransactionResult = await bscSDK.ledger.transaction.sendMultiple({
senderAccountId: '5e6645712b55823de7ea82f1',
transaction: [
{
recipientAccountId: '5e6645712b55823de7ea82f2',
amount: '5',
},
],
})
}

export async function bscLedgerVirtualCurrencyExample() {
const virtualCurrencyAcc = await bscSDK.ledger.virtualCurrency.create({
name: 'VC_VIRTUAL',
supply: '1000000',
// TODO openapi bug
basePair: VirtualCurrency.basePair.GMC_BSC,
baseRate: 1,
customer: {
// TODO openapi bug
accountingCurrency: VirtualCurrency.accountingCurrency.USD,
customerCountry: 'US',
externalId: '123654',
providerCountry: 'US',
},
description: 'My Virtual Token description.',
accountCode: 'AC_1011_B',
accountNumber: '1234567890',
// TODO openapi bug
accountingCurrency: VirtualCurrency.accountingCurrency.USD,
})

const virtualCurrency = await bscSDK.ledger.virtualCurrency.getByName('VC_VIRTUAL')

const mintTx = await bscSDK.ledger.virtualCurrency.mint({
accountId: '5e68c66581f2ee32bc354087',
amount: '1.5',
})

const revokeTx = await bscSDK.ledger.virtualCurrency.revoke({
accountId: '5e68c66581f2ee32bc354087',
amount: '1.5',
})

await bscSDK.ledger.virtualCurrency.update({
name: 'VC_VIRTUAL',
baseRate: 1,
// TODO openapi bug
basePair: VirtualCurrency.basePair.EUR,
})
}
61 changes: 61 additions & 0 deletions examples/bsc-example/src/app/bsc.nft.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { TatumBscSDK } from '@tatumio/bsc'
import { Currency } from '@tatumio/shared-core'
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'

const bscSDK = TatumBscSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function bscNftExample() {
const metadataURI = await bscSDK.nft.getNFTMetadataURI(
Currency.BSC,
'0x94Ce79B9F001E25BBEbE7C01998A78F7B27D1326',
'1',
)
const provenanceData = await bscSDK.nft.getNFTProvenanceData(
Currency.BSC,
'0x94Ce79B9F001E25BBEbE7C01998A78F7B27D1326',
'1',
)
const royalty = await bscSDK.nft.getNFTRoyalty(
Currency.BSC,
'0x94Ce79B9F001E25BBEbE7C01998A78F7B27D1326',
'1',
)
const transaction = await bscSDK.nft.getNFTTransaction(
Currency.BSC,
'0xe6e7340394958674cdf8606936d292f565e4ecc476aaa8b258ec8a141f7c75d7',
)
const nftByAddress = await bscSDK.nft.getNFTsByAddress(
Currency.BSC,
'NTAESFCB3WOD7SAOL42KSPVARLB3JFA3MNX3AESWHYVT2RMYDVZI6YLG4Y',
'0x45871ED5F15203C0ce791eFE5f4B5044833aE10e',
)

// TODO bug in openapi - chain and feeCurrency
// const minted = await bscSDK.nft.mintNFT({
// chain: Currency.BSC,
// tokenId: "100000",
// to: "0x687422eEA2cB73B5d3e242bA5456b782919AFc85",
// erc20: "0x687422eEA2cB73B5d3e242bA5456b782919AFc85",
// contractAddress: "0x687422eEA2cB73B5d3e242bA5456b782919AFc85",
// url: "https://my_token_data.com",
// authorAddresses: [
// "0x687422eEA2cB73B5d3e242bA5456b782919AFc85"
// ],
// provenance: true,
// cashbackValues: [
// "0.5"
// ],
// fixedValues: [
// "0.5"
// ],
// fromPrivateKey: "0x05e150c73f1920ec14caa1e0b6aa09940899678051a78542840c2668ce5080c2",
// nonce: 0,
// feeCurrency: Currency.BSC
// })

await bscSDK.nft.prepareAddNFTMinterAbstraction(
Currency.BSC,
'0x687422eEA2cB73B5d3e242bA5456b782919AFc85',
'1000',
)
}
34 changes: 34 additions & 0 deletions examples/bsc-example/src/app/bsc.offchain.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { TatumBscSDK } from '@tatumio/bsc'
import { REPLACE_ME_WITH_TATUM_API_KEY } from '@tatumio/shared-testing'

const bscSdk = TatumBscSDK({ apiKey: REPLACE_ME_WITH_TATUM_API_KEY })

export async function bscOffchainExample() {
const account = await bscSdk.offchain.depositAddress.checkExists(
'0xa7673161CbfE0116A4De9E341f8465940c2211d4',
)
const address = await bscSdk.offchain.depositAddress.create('0xa7673161CbfE0116A4De9E341f8465940c2211d4', 1)
const adresses = await bscSdk.offchain.depositAddress.createMultiple({
addresses: [
{
accountId: '5e6be8e9e6aa436299950c41',
derivationKey: 0,
},
{
accountId: '5e6be8e9e6aa436299951n35',
derivationKey: 1,
},
],
})
const assignedAddress = await bscSdk.offchain.depositAddress.assign(
'5e6be8e9e6aa436299950c41',
'0xa7673161CbfE0116A4De9E341f8465940c2211d4',
)
const addressByAccount = await bscSdk.offchain.depositAddress.getByAccount('5e6be8e9e6aa436299950c41')
const withdrawals = await bscSdk.offchain.withdrawal.getAll('Done')
await bscSdk.offchain.depositAddress.remove(
'5e6be8e9e6aa436299950c41',
'0xa7673161CbfE0116A4De9E341f8465940c2211d4',
)
await bscSdk.offchain.storeTokenAddress('0xa7673161CbfE0116A4De9E341f8465940c2211d4', 'MY_TOKEN')
}
Loading

0 comments on commit 668b94d

Please sign in to comment.