Skip to content

Commit

Permalink
Add READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
tifrel committed Dec 19, 2023
1 parent c1a5cf8 commit 3298c89
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 54 deletions.
45 changes: 18 additions & 27 deletions packages/sdk/src/ftDepositStorage/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
[//]: # `{ "title": "ftDepositStorage", "order": 0.15 }`

# Transfer Fungible Tokens

Transfers one or more tokens from the transaction signer to the recipient(s) specified.
# Deposit storage for FT transfers

This acts as registration for FT transfers. You cannot transfer FTs to an account that does is not registered with the corresponding FT smart contract.

**As with all new SDK api methods, this call should be wrapped in [execute](../#execute) and passed a signing method**

## transfer(args: TransferArgs): NearContractCall
## ftDepositStorage(args: FtDepositStorageArgs): NearContractCall

`transfer` takes a single argument of type `TransferArgs`
`ftDepositStorage` takes a single argument of type `FtDepositStorageArgs`

```typescript
type TransferArgs = {
// pairs of recipient and token ids,
// each recipient will receive the corresponding token
transfers: {
receiverId: string;
tokenId: string;
}[];
// nftContractId is the token contract capable of doing the transfer
// if omitted, transfer method will attempt to use process.env.CONTRACT_ADDRESS
nftContractId?: string;
type FtDepositStorageArgs = {
// The FT contract whose tokens should be transferred.
ftContractAddress: string;
// The account for which you wish to cover the storage deposit.
accountId?: string;
};
```

Expand All @@ -31,32 +25,29 @@ Example usage of transfer method in a hypothetical React component:
```typescript
import { useState } from 'react';
import { useWallet } from '@mintbase-js/react';
import { execute, transfer, TransferArgs } from '@mintbase-js/sdk';
import { execute, ftDepositStorage, FtDepositStorageArgs } from '@mintbase-js/sdk';

const TransferComponent = ({ tokenId, contractAddress }: TransferArgs): JSX.Element => {
const FtDepositStorageComponent = (): JSX.Element => {
const { selector, activeAccountId } = useWallet();

const handleTransfer = async (): Promise<void> => {
const handleFtDepositStorage = async (): Promise<void> => {
const wallet = await selector.wallet();

const transferArgs: TransferArgs = {
contractAddress: contractAddress,
transfers: [{
receiverId: 'mb_carol.testnet',
tokenId: token.tokenId,
}],
const ftDepositStorageArgs: FtDepositStorageArgs = {
ftContractAddress: "usdc.fakes.testnet",
accountId: 'mb_carol.testnet',
}

await execute(
{ wallet },
transfer(transferArgs),
ftDepositStorage(ftDepositStorageArgs),
);
};

return (
<div>
<button onClick={handleTransfer}>
Transfer {tokenId} of {contractAddress} from {activeAccountId} to Carol
<button onClick={handleFtDepositStorage}>
Register Carol with USDC
</button>
</div>
);
Expand Down
51 changes: 24 additions & 27 deletions packages/sdk/src/ftTransfer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,58 @@

# Transfer Fungible Tokens

Transfers one or more tokens from the transaction signer to the recipient(s) specified.
Transfers an amount of fungible tokens to a given account. Make sure that your recipient is [registered with the FT contract](../ftDepositStorage/README.md), and that you get the decimals of the transfer right.


**As with all new SDK api methods, this call should be wrapped in [execute](../#execute) and passed a signing method**

## transfer(args: TransferArgs): NearContractCall
## ftTransfer(args: FtTransferArgs): NearContractCall

`transfer` takes a single argument of type `TransferArgs`
`ftTransfer` takes a single argument of type `FtTransferArgs`

```typescript
type TransferArgs = {
// pairs of recipient and token ids,
// each recipient will receive the corresponding token
transfers: {
receiverId: string;
tokenId: string;
}[];
// nftContractId is the token contract capable of doing the transfer
// if omitted, transfer method will attempt to use process.env.CONTRACT_ADDRESS
nftContractId?: string;
type FtTransferArgs = {
// The FT contract whose tokens should be transferred.
ftContractAddress: string;
// The recipient of the FT transfer.
receiverId: string;
// The amount of FT to transfer in atomic units. Make sure to check the `decimals` field of this FT smart contracts metadata to avoid errors.
amount: string;
// An optional memo that you wish to send along with the transfer.
memo?: string;
};
```

Example usage of transfer method in a hypothetical React component:
{% code title="TransferComponent.ts" overflow="wrap" lineNumbers="true" %}
Example usage of FT transfer method in a hypothetical React component:
{% code title="FtTransferComponent.ts" overflow="wrap" lineNumbers="true" %}

```typescript
import { useState } from 'react';
import { useWallet } from '@mintbase-js/react';
import { execute, transfer, TransferArgs } from '@mintbase-js/sdk';
import { execute, ftTransfer, FtTransferArgs } from '@mintbase-js/sdk';

const TransferComponent = ({ tokenId, contractAddress }: TransferArgs): JSX.Element => {
const TransferComponent = (): JSX.Element => {
const { selector, activeAccountId } = useWallet();

const handleTransfer = async (): Promise<void> => {
const handleFtTransfer = async (): Promise<void> => {
const wallet = await selector.wallet();

const transferArgs: TransferArgs = {
contractAddress: contractAddress,
transfers: [{
receiverId: 'mb_carol.testnet',
tokenId: token.tokenId,
}],
const ftTransferArgs: FtTransferArgs = {
ftContractAddress: "usdc.fakes.testnet",
receiverId: "mb_carol.testnet",
amount: "10000000"
}

await execute(
{ wallet },
transfer(transferArgs),
ftTransfer(ftTransferArgs),
);
};

return (
<div>
<button onClick={handleTransfer}>
Transfer {tokenId} of {contractAddress} from {activeAccountId} to Carol
<button onClick={handleFtTransfer}>
Transfer 10 USDC to Carol
</button>
</div>
);
Expand Down

0 comments on commit 3298c89

Please sign in to comment.