> For the complete documentation index, see [llms.txt](https://tabasco.gitbook.io/amity/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tabasco.gitbook.io/amity/overview/transactions.md).

# Transactions

Explanation of transaction handling

## Preface

Amity offers on-chain token transactions between either discord users or outside public addresses.

#### How this works

After fetching [account information](/amity/overview/account-handling.md) and [preferred network](/amity/overview/networks.md), a transaction is built using the following command fields:

```
/send (value) (to) (*contract)
```

The transaction building and signing looks like this:

```python
estimate = web3.eth.estimateGas({'to': to, 'from': address, 'value': int(web3.toWei(value, 'ether'))})
tx = {
    'nonce': web3.eth.get_transaction_count(address),
    'to': to, 
    'value': web3.toWei(value, 'ether'), 
    'gas': estimate, 
    'gasPrice': web3.eth.gasPrice
    }
signed_tx = web3.eth.account.sign_transaction(tx, decryptedPrivateKey) 
```

{% embed url="<https://www.youtube.com/watch?v=YjGaQbitvaA>" %}

## Contract/token transactions

If a contract is specified in the "\*contract" field, the code looks slightly different as a transaction has to instead be built through a web3 contract object instead of a default tx dictionary.

First, the contract object has to be initialized through a Checksum address and ABI:

```python
contract = web3.eth.contract(address=Web3.toChecksumAddress(contract), abi=abi)
```

Web3 requires that contracts are called in a Checksum format, so the toChecksum of the contract provided is plugged into the contract object. The ABI used is a generic ERC20 file pulled from a separate file. After this, the transaction can begin to be built in a similar fashion to a normal coin (non-token) transaction:

```python
estimate = contract.functions.transfer(to, int(amount)).estimateGas({'from': address, 'chainId': chainId})
tx = contract.functions.transfer(
  to, web3.toWei(value, 'ether')
  ).buildTransaction({
    'chainId': chainId,
    'gas': estimate,
    'gasPrice': web3.eth.gasPrice,
    'nonce': web3.eth.get_transaction_count(address),
  })
signed_tx = web3.eth.account.sign_transaction(tx, decryptedPrivateKey)
```

Due to Amity utilizing contracts dynamically and by using generic ABI's, you can access and send any token just by referencing the contract address.
