Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions build-on-celo/build-on-minipay/code-library.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ console.log(attestations.accounts);

## Request an ERC20 token transfer

<Warning>
USDT and USDC on Celo use **6 decimals**, not 18. Pass `tokenDecimals` as `6` when
transferring either token. Using `18` will send 1,000,000,000,000× more than intended.
USDm uses 18 decimals.
</Warning>

```js
import { createWalletClient, createPublicClient, custom, http, encodeFunctionData, parseUnits } from "viem";
import { celo, celoSepolia } from "viem/chains";
Expand All @@ -378,16 +384,16 @@ const publicClient = createPublicClient({
async function requestTransfer(tokenAddress, transferValue, tokenDecimals, receiverAddress) {
const hash = await walletClient.sendTransaction({
to: tokenAddress,
// Mainnet addresses:
// USDm: '0x765DE816845861e75A25fCA122bb6898B8B1282a'
// USDC: '0xcebA9300f2b948710d2653dD7B07f33A8B32118C'
// USDT: '0x48065fbbe25f71c9282ddf5e1cd6d6a887483d5e'
// Mainnet token addresses and their decimals:
// USDm: '0x765DE816845861e75A25fCA122bb6898B8B1282a' (18 decimals)
// USDC: '0xcebA9300f2b948710d2653dD7B07f33A8B32118C' (6 decimals)
// USDT: '0x48065fbbe25f71c9282ddf5e1cd6d6a887483d5e' (6 decimals)
data: encodeFunctionData({
abi: stableTokenABI, // Token ABI from @celo/abis
functionName: "transfer",
args: [
receiverAddress,
// Different tokens can have different decimals, USDm (18), USDC (6)
// USDm uses 18 decimals; USDC and USDT use 6 decimals
parseUnits(`${Number(transferValue)}`, tokenDecimals),
],
}),
Expand Down
13 changes: 12 additions & 1 deletion build-on-celo/fee-abstraction/using-fee-abstraction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ celocli transfer:erc20 \
--privateKey [PRIVATE_KEY]
```

When using USDC or USDT, use the adapter address (not the token address) to avoid inaccuracies caused by their 6-decimal precision.
When using USDC or USDT, use the **adapter address** (not the token address) as `--gasCurrency`. Both tokens use 6 decimals — pass `--value` in units of `10^6` (e.g. `1000000` = 1 USDT/USDC).

Transfer 1 USDT using USDT as the fee currency:
```bash
celocli transfer:erc20 \
--erc20Address 0x48065fbbe25f71c9282ddf5e1cd6d6a887483d5e \
--from 0x22ae7Cf4cD59773f058B685a7e6B7E0984C54966 \
--to 0xDF7d8B197EB130cF68809730b0D41999A830c4d7 \
--value 1000000 \
--gasCurrency 0x0e2a3e05bc9a16f5292a6170456a710cb89c6f72 \
--privateKey [PRIVATE_KEY]
```

---

Expand Down