# Avalanche Contract Chain (C-Chain)

Source: https://developers.bitgo.com/docs/avalanche-contract-chain-(c-chain)

## Avalanche Contract Chain (C-Chain)

Avalanche can be accessed with the following coin types

| Environment             | Coin Type | Faucet                                                                                                             |
| :---------------------- | :-------- | :----------------------------------------------------------------------------------------------------------------- |
| Avax C-Chain Production | avaxc     |
| Avax C-Chain Testnet    | tavaxc    | <a href="https://faucet.avax-test.network/" target="_blank" rel="noreferrer">https://faucet.avax-test.network/</a> |

### Explorer
<a href="https://subnets.avax.network/c-chain" target="_blank" rel="noreferrer">https://subnets.avax.network/c-chain</a>


### Enterprise fee address

```shell
ENTERPRISEID=585c51a5df8380e0e3082e46

curl -X POST \
-H "Authorization: Bearer $ACCESS_TOKEN" \
https://app.bitgo-test.com/api/v2/tavaxc/enterprise/$ENTERPRISEID/feeAddressBalance
```

The C-Chain is an instance of the Ethereum Virtual Machine (EVM). Each enterprise has a fee address used
to pay for transaction fees on all Avalanche C-Chain wallets in that enterprise. The BitGo website dashboard displays the fee address, and you must fund it before creating a wallet, address, or sending a transaction. If the
enterprise fee address insufficient balance, you cannot create new wallets, addresses, or send transactions
until you fund the fee address. You cannot use one of your own Avalanche C-Chain wallets to fund the fee
address if the fee address is too low (because you cannot send transactions from your Avalanche C-Chain
wallet). It is best to create and fund a non-BitGo Avalanche C-Chain account, so you can use it to fund your BitGo
enterprise fee address. Any open source Avalanche C-Chain wallet can be used to create an account.

Please note that the fee address is a single-signature account, and that BitGo creates and owns the private key.
You cannot send assets out of the fee address once you have sent them in.

There is a `feeAddress` field under the `CoinSpecific` key for Avalanche C-Chain wallets. Use this address
to pay the fees for creating transactions and addresses.

### Wallet construction

```javascript
bitgo
  .coin('tavaxc')
  .wallets()
  .generateWallet({
    label: 'My Test Wallet',
    passphrase: 'secretpassphrase1a5df8380e0e30',
    enterprise: '5612c2beeecf83610b621b90964448cd',
  })
  .then(function (wallet) {
    // print the new wallet
    console.dir(wallet);
  });
```
```shell
LABEL="My Test Wallet"
PASSPHRASE="secretpassphrase1a5df8380e0e30"

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d "{ \"label\": \"$LABEL\", \"passphrase\": \"$PASSPHRASE\" }" \
http://$BITGO_EXPRESS_HOST/api/v2/tavaxc/wallet/generate
```

Avalanche C-Chain wallets can only be created under an enterprise. You must pass in the id of the enterprise to
associate the wallet with.

The creation of Avalanche C-Chain wallets requires interaction with the Avalanche ledger to be complete. When you create
an Avalanche C-Chain wallet, BitGo sends an initialization transaction on the Avalanche network to create the
wallet. While these initialization transactions remain unconfirmed, the wallet should not be used, nor should anyone
attempt to send assets to the wallet. For this reason, while the wallet initialization transactions are still
unconfirmed on the Avalanche C-Chain network, the wallet receive address is _not_ visible through the API. This
is to protect users against sending to a Avalanche C-Chain wallet which does not exist on the network and losing assets.

```javascript
bitgo
  .coin('tavaxc')
  .wallets()
  .getWallet({ id: '585c51a5df8380e0e3082e46' })
  .then(function (wallet) {
    return wallet.createAddress();
  })
  .then(function (newAddress) {
    // print new address details
    console.dir(newAddress);
  });
```
```shell
WALLET=585c51a5df8380e0e3082e46

curl -X POST \
-H "Authorization: Bearer $ACCESS_TOKEN" \
https://app.bitgo-test.com/api/v2/tavaxc/wallet/$WALLET/address
```

Avalanche C-Chain address creation requires interactions with the Avalanche blockchain. To deploy a receive
address contract, BitGo sends a transaction on the Avalanche C-Chain network. Please make sure to fund the fee address
mentioned earlier. Like the wallet creation process, a Avalanche C-Chain address is not immediately usable upon
creation and so the caller of this function needs to wait for the initialization transaction to be confirmed before
attempting to fetch the address or send assets to it.

### Balances

Each Avax consists of `1,000,000,000,000,000,000` (<code>10<sup>18</sup></code>) wei, so not even a single Avax can
be stored numerically without exceeding the range of Javascript numbers.

For that reason, only string balance properties are available, which are `balanceString`, `confirmedBalanceString`, and
`spendableBalanceString`.

### Transactions

BitGo's Avalanche C-Chain multisig contract currently only supports one sender and one recipient. That means that the
`sendMany` call only accepts one recipient.
