# ONG Contract API

{% hint style="info" %}
Please install Ontology [SDKs ](https://docs.ont.io/developer-tools/sdk)before using the APIs introduced below.
{% endhint %}

## Index

* [`BalanceOf`](#balanceof)
* [`BalanceOfV2`](#balanceofv2)
* [`Transfer`](#transfer)
* [`TransferV2`](#transferv2)
* [`MultiTransfer`](#multitransfer)
* [`MultiTransferV2`](#multitransferv2)
* [`Approve`](#approve)
* [`ApproveV2`](#approvev2)
* [`Allowance`](#allowance)
* [`AllowanceV2`](#allowancev2)
* [`TransferFrom`](#transferfrom)
* [`TransferFromV2`](#transferfromv2)
* [`WithdrawONG`](#withdrawong)
* [`UnboundONG`](#unboundong)

## Methods

### `BalanceOf`

Fetch the balance of a specific address.

```
ontSdk.Native.Ong.BalanceOf(address common.Address) (uint64, error)
```

### `BalanceOfV2`

Fetch the balance of a specific address.

ONG has 18 decimals.

```
ontSdk.Native.Ong.BalanceOfV2(address common.Address) (*big.Int, error)
```

### `Transfer`

Initiate a transaction.&#x20;

```
ontSdk.Native.Ong.Transfer(gasPrice, gasLimit uint64, from *Account, to common.Address, amount uint64) (common.Uint256, error)
```

Emit a corresponding contract event. For example:

```json
{
"ContractAddress": "0200000000000000000000000000000000000000",
"States": [
"transfer",
"APS1wGGVUjsJYLUvncckzgsdqGT3KRqMtx",
"AFmseVrdL9f9oyCzZefL9tG6UbviEH9ugK",
50000000
]
}
```

### `TransferV2`

Initiate a transaction.&#x20;

ONG has 18 decimals.

```
ontSdk.Native.Ong.TransferV2(gasPrice, gasLimit uint64, from *Account, to common.Address, amount *big.Int) (common.Uint256, error)
```

If the transfer amount is divisible by 10^9, the event emitted will be the same as the one by `Transfer`.

Otherwise, the amount consists of two integers. The first one represents `amount`/10^9, and the second one represents `amount`%10^9. For example, if the transaction amount is 0.050000000123456789 ONG, the event looks like:

```json
{
"ContractAddress": "0200000000000000000000000000000000000000",
"States": [
"transfer",
"APS1wGGVUjsJYLUvncckzgsdqGT3KRqMtx",
"AFmseVrdL9f9oyCzZefL9tG6UbviEH9ugK",
50000000,
123456789
]
}
```

### `MultiTransfer`

Initiate a batch transfer from one address to multiple addresses.

```
ontSdk.Native.Ong.MultiTransfer(gasPrice, gasLimit uint64, states []*ont.State, signer *Account) (common.Uint256, error)
```

### `MultiTransferV2`

Initiate a batch transfer from one address to multiple addresses.

ONG has 18 decimals.

```
ontSdk.Native.Ong.MultiTransferV2(gasPrice, gasLimit uint64, states []*ont.State, signer *Account) (common.Uint256, error)
```

### `Approve`

Approve tokens to be withdrawn as allowance.&#x20;

```
ontSdk.Native.Ong.Approve(gasPrice, gasLimit uint64, from *Account, to common.Address, amount uint64) (common.Uint256, error)
```

### `ApproveV2`

Approve tokens to be withdrawn as allowance.&#x20;

ONG has 18 decimals.

```
ontSdk.Native.Ong.ApproveV2(gasPrice, gasLimit uint64, from *Account, to common.Address, amount *big.Int) (common.Uint256, error)
```

### `Allowance`

Return the allowance from the `from` account to the `to` account.

```
ontSdk.Native.Ong.Allowance(from, to common.Address) (uint64, error)
```

### `AllowanceV2`

Return the allowance from the `from` account to the `to` account.

ONG has 18 decimals.

```
ontSdk.Native.Ong.AllowanceV2(from, to common.Address) (*big.Int, error)
```

### `TransferFrom`

Allow tokens to be transferred from allowance.

```
ontSdk.Native.Ong.TransferFrom(gasPrice, gasLimit uint64, sender *Account, from, to common.Address, amount uint64) (common.Uint256, error)
```

### `TransferFromV2`

Allow tokens to be transferred from allowance.

ONG has 18 decimals.

```
ontSdk.Native.Ong.TransferFrom(gasPrice, gasLimit uint64, sender *Account, from, to common.Address, amount *big.Int) (common.Uint256, error)
```

### `WithdrawONG`

Withdraw generated ONG.

```
ontSdk.Native.Ong.WithdrawONG(gasPrice, gasLimit uint64, address *Account, amount uint64) (common.Uint256, error)
```

### `UnboundONG`

Calculate the amount of ONG generated.

```
ontSdk.Native.Ong.UnboundONG(address common.Address) (uint64, error)
```
