Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion website/pages/en/developing/graph-ts/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: AssemblyScript API

This page documents what built-in APIs can be used when writing subgraph mappings. Two kinds of APIs are available out of the box:

- the [Graph TypeScript library](https://github.com/graphprotocol/graph-ts) (`graph-ts`) and
- the [Graph TypeScript library](https://github.com/graphprotocol/graph-tooling) (`graph-ts`) and
- code generated from subgraph files by `graph codegen`.

It is also possible to add other libraries as dependencies, as long as they are compatible with [AssemblyScript](https://github.com/AssemblyScript/assemblyscript). Since this is the language mappings are written in, the [AssemblyScript wiki](https://github.com/AssemblyScript/assemblyscript/wiki) is a good source for language and standard library features.
Expand Down Expand Up @@ -536,6 +536,17 @@ For more information:
- Encoding/decoding [Rust library/CLI](https://github.com/rust-ethereum/ethabi)
- More [complex example](https://github.com/graphprotocol/graph-node/blob/6a7806cc465949ebb9e5b8269eeb763857797efc/tests/integration-tests/host-exports/src/mapping.ts#L72).

#### Balance of an Address

The balance of an address can be retrieved using the `ethereum` module. This feature is available from `apiVersion: 0.0.9` defined `subgraph.yaml`. The `getBalance()` retrieves the balance of the specified address from the block currently being processed within the subgraph.

```typescript
import { ethereum } from '@graphprotocol/graph-ts'

let address = Address.fromString('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
let balance = ethereum.getBalance(address) // returns balance in BigInt
```

### Logging API

```typescript
Expand Down