> For the complete documentation index, see [llms.txt](https://docs.learncard.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.learncard.com/reference/official-plugins/ethereum.md).

# Ethereum

A plugin for interacting with the Ethereum blockchain

## Installation

```bash
bun add @learncard/ethereum-plugin
```

## Instantiation

To use this plugin, you must include an `ethereumConfig` object as a part of the LearnCardConfig parameter for `initLearnCard`

```typescript
const learnCard = await initLearncard({
    seed: privateKey,
    // ...
    ethereumConfig: {
        network: 'mainnet',
        infuraProjectId: 'abc123',
    },
});
```

#### network (optional)

The Ethereum network to connect to. This is an ethers [Networkish](https://docs.ethers.io/v5/api/providers/types/#providers-Networkish) type, which can be a [Network](https://docs.ethers.io/v5/api/providers/types/#providers-Network) object, the name of a network as a string, or the chain ID of a network as a number.

Defaults to 'mainnet' if not provided

#### infuraProjectId (optional)

The [Infura](https://infura.io/) project ID that you would like to use to access the Ethereum network.

If not provided, the [default ethers provider](https://docs.ethers.io/v5/api/providers/#providers-getDefaultProvider) will be used.

## Methods

#### getEthereumAddress()

Returns the Ethereum public address associated with this wallet

#### async getBalance(symbolOrAddress)

Returns the token balance for this wallet for the given symbol or token address

`await learnCard.getBalance('ETH')`

* symbolOrAddress - string (optional)
  * The ERC20 token address for the token you wish to check the balance of

    `learnCard.getBalance('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48') // USDC on mainnet`
  * The token symbol for the token you wish to check the balance of

    `learnCard.getBalance('USDC')`

    * Note: this will only work if the given symbol is recognized.
  * Defaults to 'ETH' if omitted

#### async getBalanceForAddress(walletAddress, symbolOrAddress)

Returns the token balance for the given wallet address for the given symbol/token address

`await learnCard.getBalanceForAddress('0xAddressToCheck', 'DAI')`

* walletAddress - string
  * The public address you wish to check the balance for
* symbolOrAddress - string (optional)
  * Same as[ getBalance's symbolOrAddress](#async-getbalance-symboloraddress)

#### async transferTokens(tokenSymbolOrAddress, amount, toAddress)

Transfers tokens from this wallet to another wallet. Returns the transaction hash.

`await wallet.transferTokens('USDC', 2.2, '0xAddressToSendTo')`

* tokenSymbolOrAddress - string
  * Same as [getBalance's symbolOrAddress](#async-getbalance-symboloraddress)
* amount - number
  * The number of tokens you wish to transfer
* toAddress - string
  * The address that you wish to send tokens to

#### async getGasPrice()

Get the current gas price for the network

`await wallet.getGasPrice()`

#### getCurrentNetwork()

Returns the current Ethereum network (type: [Networkish](#async-getbalance-symboloraddress))

#### changeNetwork(\_network)

Changes the current Ethereum network

* \_network - [Networkish](#async-getbalance-symboloraddress)

#### addInfuraProjectId(infuraProjectId)

Add or change the Infura project ID

* infuraProjectId - string
  * The new infura project ID that you wish to use

####


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.learncard.com/reference/official-plugins/ethereum.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
