> For the complete documentation index, see [llms.txt](https://docs.play.cronos.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.play.cronos.org/readme-1/classes/structorg_1_1defi__wallet__core_1_1_erc20.md).

# org::defi\_wallet\_core::Erc20

## org::defi\_wallet\_core::Erc20

`#include <contract.rs.h>`

### Public Types

|                         | Name                                      |
| ----------------------- | ----------------------------------------- |
| using ::std::true\_type | [**IsRelocatable**](#using-isrelocatable) |

### Public Functions

|                                                                                                                                                   | Name                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ::[org::defi\_wallet\_core::U256](/readme-1/classes/structorg_1_1defi__wallet__core_1_1_u256.md)                                                  | <p><a href="#function-balance-of"><strong>balance\_of</strong></a>(::<a href="/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md">rust::String</a> account\_address) const<br>Returns the decimal amount of tokens owned by <code>account\_address</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                 |
| ::[rust::String](/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md)                                                                         | <p><a href="#function-name"><strong>name</strong></a>() const<br>Returns the name of the token.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ::[rust::String](/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md)                                                                         | <p><a href="#function-symbol"><strong>symbol</strong></a>() const<br>Returns the symbol of the token.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ::std::uint8\_t                                                                                                                                   | <p><a href="#function-decimals"><strong>decimals</strong></a>() const<br>Returns the number of decimals the token uses.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ::[org::defi\_wallet\_core::Erc20](/readme-1/classes/structorg_1_1defi__wallet__core_1_1_erc20.md)                                                | <p><a href="#function-legacy"><strong>legacy</strong></a>()<br>Makes a legacy transaction instead of an EIP-1559 one.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ::[org::defi\_wallet\_core::Erc20](/readme-1/classes/structorg_1_1defi__wallet__core_1_1_erc20.md)                                                | <p><a href="#function-interval"><strong>interval</strong></a>(::std::uint64\_t polling\_interval\_ms)<br>Sets the default polling interval for event filters and pending transactions.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ::[org::defi\_wallet\_core::CronosTransactionReceiptRaw](/readme-1/classes/structorg_1_1defi__wallet__core_1_1_cronos_transaction_receipt_raw.md) | <p><a href="#function-transfer"><strong>transfer</strong></a>(::<a href="/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md">rust::String</a> to\_address, ::<a href="/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md">rust::String</a> amount, ::<a href="/readme-1/classes/structorg_1_1defi__wallet__core_1_1_private_key.md">org::defi\_wallet\_core::PrivateKey</a> const & private\_key) const<br>Moves <code>amount</code> tokens from the caller’s account to <code>to\_address</code>.</p>                                                                                                                                                    |
| ::[org::defi\_wallet\_core::CronosTransactionReceiptRaw](/readme-1/classes/structorg_1_1defi__wallet__core_1_1_cronos_transaction_receipt_raw.md) | <p><a href="#function-transfer-from"><strong>transfer\_from</strong></a>(::<a href="/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md">rust::String</a> from\_address, ::<a href="/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md">rust::String</a> to\_address, ::<a href="/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md">rust::String</a> amount, ::<a href="/readme-1/classes/structorg_1_1defi__wallet__core_1_1_private_key.md">org::defi\_wallet\_core::PrivateKey</a> const & private\_key) const<br>Moves <code>amount</code> tokens from <code>from\_address</code> to <code>to\_address</code> using the allowance mechanism.</p> |
| ::[org::defi\_wallet\_core::CronosTransactionReceiptRaw](/readme-1/classes/structorg_1_1defi__wallet__core_1_1_cronos_transaction_receipt_raw.md) | <p><a href="#function-approve"><strong>approve</strong></a>(::<a href="/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md">rust::String</a> approved\_address, ::<a href="/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md">rust::String</a> amount, ::<a href="/readme-1/classes/structorg_1_1defi__wallet__core_1_1_private_key.md">org::defi\_wallet\_core::PrivateKey</a> const & private\_key) const<br>Allows <code>approved\_address</code> to withdraw from your account multiple times, up to the <code>amount</code> amount.</p>                                                                                                              |
| ::[rust::String](/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md)                                                                         | <p><a href="#function-allowance"><strong>allowance</strong></a>(::<a href="/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md">rust::String</a> owner, ::<a href="/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md">rust::String</a> spender) const<br>Returns the amount which <code>spender</code> is still allowed to withdraw from <code>owner</code>.</p>                                                                                                                                                                                                                                                                                          |
| ::[org::defi\_wallet\_core::U256](/readme-1/classes/structorg_1_1defi__wallet__core_1_1_u256.md)                                                  | <p><a href="#function-total-supply"><strong>total\_supply</strong></a>() const<br>Returns the amount of tokens in existence.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

### Public Attributes

|                                                                           | Name                                                                    |
| ------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| ::[rust::String](/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md) | [**contract\_address**](#variable-contract-address)                     |
| ::[rust::String](/readme-1/classes/classrust_1_1cxxbridge1_1_1_string.md) | [**web3api\_url**](#variable-web3api-url)                               |
| bool                                                                      | [**inner\_legacy**](#variable-inner-legacy)                             |
| ::std::uint64\_t                                                          | [**inner\_polling\_interval\_ms**](#variable-inner-polling-interval-ms) |
| ::std::uint64\_t                                                          | [**chain\_id**](#variable-chain-id)                                     |

### Public Types Documentation

#### using IsRelocatable

```cpp
using org::defi_wallet_core::Erc20::IsRelocatable =  ::std::true_type;
```

### Public Functions Documentation

#### function balance\_of

```cpp
::org::defi_wallet_core::U256 balance_of(
    ::rust::String account_address
) const
```

Returns the decimal amount of tokens owned by `account_address`.

## Examples

```cpp
Erc20 erc20 = new_erc20("0xf0307093f23311FE6776a7742dB619EB3df62969",
   "https://evm-dev-t3.cronos.org", 338)
 .legacy();
U256 = erc20.balance_of("0xf0307093f23311FE6776a7742dB619EB3df62969");
cout << balance.to_string() << endl;
```

#### function name

```cpp
::rust::String name() const
```

Returns the name of the token.

```cpp
Erc20 erc20 = new_erc20("0xf0307093f23311FE6776a7742dB619EB3df62969",
   "https://evm-dev-t3.cronos.org", 338);
String name = erc20.name();
assert(name == "USDC");
```

#### function symbol

```cpp
::rust::String symbol() const
```

Returns the symbol of the token.

```cpp
Erc20 erc20 = new_erc20("0xf0307093f23311FE6776a7742dB619EB3df62969",
   "https://evm-dev-t3.cronos.org", 338);
String symbol = erc20.symbol();
assert(symbol == "USDC");
```

#### function decimals

```cpp
::std::uint8_t decimals() const
```

Returns the number of decimals the token uses.

```cpp
Erc20 erc20 = new_erc20("0xf0307093f23311FE6776a7742dB619EB3df62969",
   "https://evm-dev-t3.cronos.org", 338)
 .legacy();
uint8_t decimals = erc20.decimals();
assert(decimals == 6);
```

#### function legacy

```cpp
::org::defi_wallet_core::Erc20 legacy()
```

Makes a legacy transaction instead of an EIP-1559 one.

```cpp
Erc20 erc20 = new_erc20("0xf0307093f23311FE6776a7742dB619EB3df62969",
   "https://evm-dev-t3.cronos.org", 338);
erc20 = erc20.legacy();
```

#### function interval

```cpp
::org::defi_wallet_core::Erc20 interval(
    ::std::uint64_t polling_interval_ms
)
```

Sets the default polling interval for event filters and pending transactions.

```cpp
Erc20 erc20 = new_erc20("0xf0307093f23311FE6776a7742dB619EB3df62969",
   "https://evm-dev-t3.cronos.org", 338);
erc20 = erc20.interval(3000);
```

#### function transfer

```cpp
::org::defi_wallet_core::CronosTransactionReceiptRaw transfer(
    ::rust::String to_address,
    ::rust::String amount,
    ::org::defi_wallet_core::PrivateKey const & private_key
) const
```

Moves `amount` tokens from the caller’s account to `to_address`.

## Transfer 100 tokens (devnet)

```cpp
String mycronosrpc = getEnv("MYCRONOSRPC");
char hdpath[100];
int cointype = 60;
int chainid = 777;
snprintf(hdpath, sizeof(hdpath), "m/44'/%d'/0'/0/0", cointype);

String signer1_mnemonics = getEnv("SIGNER1_MNEMONIC");
Box<Wallet> signer1_wallet = createWallet(signer1_mnemonics);
String signer1_address = signer1_wallet->get_eth_address(0);
Box<PrivateKey> signer1_privatekey = signer1_wallet->get_key(hdpath);

String signer2_mnemonics = getEnv("SIGNER2_MNEMONIC");
Box<Wallet> signer2_wallet = createWallet(signer2_mnemonics);
String signer2_address = signer2_wallet->get_eth_address(0);
Box<PrivateKey> signer2_privatekey = signer2_wallet->get_key(hdpath);

Erc20 erc20 = new_erc20("0x5003c1fcc043D2d81fF970266bf3fa6e8C5a1F3A",
                        mycronosrpc, chainid)
                .legacy();
erc20.transfer(signer2_address, "100", *privatekey);
```

#### function transfer\_from

```cpp
::org::defi_wallet_core::CronosTransactionReceiptRaw transfer_from(
    ::rust::String from_address,
    ::rust::String to_address,
    ::rust::String amount,
    ::org::defi_wallet_core::PrivateKey const & private_key
) const
```

Moves `amount` tokens from `from_address` to `to_address` using the allowance mechanism.

## Transfer from signer1 to validator1 using the allowance mechanism (devnet)

```cpp
String mycronosrpc = getEnv("MYCRONOSRPC");
char hdpath[100];
int cointype = 60;
int chainid = 777;
snprintf(hdpath, sizeof(hdpath), "m/44'/%d'/0'/0/0", cointype);

String signer1_mnemonics = getEnv("SIGNER1_MNEMONIC");
Box<Wallet> signer1_wallet = createWallet(signer1_mnemonics);
String signer1_address = signer1_wallet->get_eth_address(0);
Box<PrivateKey> signer1_privatekey = signer1_wallet->get_key(hdpath);

String signer2_mnemonics = getEnv("SIGNER2_MNEMONIC");
Box<Wallet> signer2_wallet = createWallet(signer2_mnemonics);
String signer2_address = signer2_wallet->get_eth_address(0);
Box<PrivateKey> signer2_privatekey = signer2_wallet->get_key(hdpath);

Erc20 erc20 = new_erc20("0x5003c1fcc043D2d81fF970266bf3fa6e8C5a1F3A",
                        mycronosrpc, chainid)
                .legacy();
erc20.transfer_from(signer1_address, validator1_address, "100",
                *signer2_privatekey);
```

#### function approve

```cpp
::org::defi_wallet_core::CronosTransactionReceiptRaw approve(
    ::rust::String approved_address,
    ::rust::String amount,
    ::org::defi_wallet_core::PrivateKey const & private_key
) const
```

Allows `approved_address` to withdraw from your account multiple times, up to the `amount` amount.

### approves 1000 allowance (devnet)

```cpp
String mycronosrpc = getEnv("MYCRONOSRPC");
char hdpath[100];
int cointype = 60;
int chainid = 777;
snprintf(hdpath, sizeof(hdpath), "m/44'/%d'/0'/0/0", cointype);

String signer1_mnemonics = getEnv("SIGNER1_MNEMONIC");
Box<Wallet> signer1_wallet = createWallet(signer1_mnemonics);
String signer1_address = signer1_wallet->get_eth_address(0);
Box<PrivateKey> signer1_privatekey = signer1_wallet->get_key(hdpath);

String signer2_mnemonics = getEnv("SIGNER2_MNEMONIC");
Box<Wallet> signer2_wallet = createWallet(signer2_mnemonics);
String signer2_address = signer2_wallet->get_eth_address(0);
Box<PrivateKey> signer2_privatekey = signer2_wallet->get_key(hdpath);

Erc20 erc20 = new_erc20("0x5003c1fcc043D2d81fF970266bf3fa6e8C5a1F3A",
                        mycronosrpc, chainid)
                .legacy();
erc20.interval(3000).approve(signer2_address, "1000", *signer1_privatekey);
```

#### function allowance

```cpp
::rust::String allowance(
    ::rust::String owner,
    ::rust::String spender
) const
```

Returns the amount which `spender` is still allowed to withdraw from `owner`.

```cpp
Erc20 erc20 = new_erc20("0x5003c1fcc043D2d81fF970266bf3fa6e8C5a1F3A",
                        mycronosrpc, chainid)
                .legacy();
erc20.allowance(owner, spender);
```

#### function total\_supply

```cpp
::org::defi_wallet_core::U256 total_supply() const
```

Returns the amount of tokens in existence.

```cpp
Erc20 erc20 = new_erc20("0xf0307093f23311FE6776a7742dB619EB3df62969",
                        "https://evm-dev-t3.cronos.org", 338)
                .legacy();
U256 total_supply = erc20.total_supply();
```

### Public Attributes Documentation

#### variable contract\_address

```cpp
::rust::String contract_address;
```

#### variable web3api\_url

```cpp
::rust::String web3api_url;
```

#### variable inner\_legacy

```cpp
bool inner_legacy;
```

#### variable inner\_polling\_interval\_ms

```cpp
::std::uint64_t inner_polling_interval_ms;
```

#### variable chain\_id

```cpp
::std::uint64_t chain_id;
```

***

Updated on 2023-01-11 at 18:25:18 +0800
