Skip to content

Commit

Permalink
chore!: remove Bech32 address (#3493)
Browse files Browse the repository at this point in the history
* chore: removed bech32

* chore: update recipes

* chore: fix test

* chore: update changeset

* Update apps/docs/src/guide/types/address.md

Co-authored-by: Daniel Bate <[email protected]>

---------

Co-authored-by: Anderson Arboleya <[email protected]>
Co-authored-by: Daniel Bate <[email protected]>
  • Loading branch information
3 people authored Jan 2, 2025
1 parent c6895b6 commit 4ccc628
Show file tree
Hide file tree
Showing 41 changed files with 135 additions and 519 deletions.
8 changes: 8 additions & 0 deletions .changeset/small-plums-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@fuel-ts/address": minor
"@fuel-ts/errors": patch
"@fuel-ts/recipes": patch
"@fuel-ts/logger": minor
---

chore!: remove Bech32 address
7 changes: 1 addition & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,7 @@ During the CI process an automated end-to-end (e2e) test is executed. This test
The e2e test can be found at:
`packages/fuel-gauge/src/e2e-script.test.ts`

The Bech32 address of this wallet is `fuel1x33ajpj0jy5p2wcqqu45e32r75zrwfeh6hwqfv5un670rv4p0mns58enjg`. This address can be funded via the [faucet](https://faucet-testnet.fuel.network/).

> [!NOTE] Note
> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
The B256 address of this wallet is `0x3463d9064f9128153b00072b4cc543f504372737d5dc04b29c9ebcf1b2a17ee7`. This address can be funded via the [faucet](https://faucet-testnet.fuel.network/).

If you want to run an e2e test locally, you can provide your own wallet address and private key. For obvious security reasons, the private key should not be shared.

Expand All @@ -270,8 +267,6 @@ This will enable you to run the e2e test locally against the live network:
pnpm test:filter e2e-script
```

<!-- TODO: add/fix block explorer URL after testnet support- Checking Wallet Balance: https://fuellabs.github.io/block-explorer-v2/beta-5/?#/address/fuel1x33ajpj0jy5p2wcqqu45e32r75zrwfeh6hwqfv5un670rv4p0mns58enjg -->

# Commit Convention

Before you create a Pull Request, please check whether your commits comply with
Expand Down
4 changes: 0 additions & 4 deletions apps/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,6 @@ export default defineConfig({
text: 'Asset Id',
link: '/guide/types/asset-id',
},
{
text: 'Bech32',
link: '/guide/types/bech32',
},
{
text: 'Bits256',
link: '/guide/types/bits256',
Expand Down
1 change: 0 additions & 1 deletion apps/docs/spell-check-custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ backends
backoff
backtrace
backtraces
Bech
BigNumber
Bitfield
bitmask
Expand Down
7 changes: 2 additions & 5 deletions apps/docs/src/guide/contracts/managing-deployed-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ To interact with a deployed contract using the SDK without redeploying it, you o

The `contractId` property from the [`Contract`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) class is of type [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html), an abstract class that is exclusively extended by the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class.

The [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class wraps all methods from the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html) class and adds a single property: `bech32Address`. This property is a string encoded in [`Bech32`](../types/bech32.md) format, recognizable by the human-readable prefix `fuel` followed by the separator `1`.

> [!NOTE] Note
> `Bech32` addresses like `fuel1..` are now deprecated; please switch to B256 format, for more details see [here](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256).
The [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class wraps all methods from the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html) class and adds a single property: `b256Address`. This property is a string encoded in [`B256`](../types/bits256.md) format.

When you log the `contractId` property of an instantiated Contract using `console.log`, the output appears as follows:

```console
Address {
bech32Address: 'fuel1e5tdjlzufcvwut5dvs5yglweepmrevpnvuvt2djj6pyl3mygkwaq8m7f20'
b256Address: '0xcd16d97c5c4e18ee2e8d6428447dd9c8763cb0336718b53652d049f8ec88b3ba'
}
```

Expand Down
19 changes: 5 additions & 14 deletions apps/docs/src/guide/types/address.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,31 @@ The SDK defines the [AbstractAddress](https://fuels-ts-docs-api.vercel.app/class

## Address Class

Besides conforming to the interface of the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html), the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class also defines one property; `bech32Address`, which is of the [`Bech32`](./bech32.md) type.
Besides conforming to the interface of the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html), the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class also defines one property; `b256Address`, which is of the [`B256`](./bits256.md) type.

<<< @/../../../packages/address/src/address.ts#address-2{ts:line-numbers}

## Creating an Address

Thanks to the utility functions provided by the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html) class, there are several ways to create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) instance:

### From a `Bech32` Address
### From a b256 address

To create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from a `Bech32` address, use the following code snippet:

<<< @./snippets/address/creating-an-address.ts#full{ts:line-numbers}
To create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from a 256-bit address, use the following code snippet:

> [!NOTE] Note
> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
<<< @./snippets/address/from-a-b256.ts#full{ts:line-numbers}

### From a Public Key

To create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from a public key, use the following code snippet:

<<< @./snippets/address/from-a-public-key.ts#full{ts:line-numbers}

### From a 256-bit Address

To create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from a 256-bit address, use the following code snippet:

<<< @./snippets/address/from-a-b256.ts#full{ts:line-numbers}

## Utility Functions

The [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class also provides some practical utility functions:

1. `fromString`: Create a new [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from an ambiguous source that may be a `Bech32` or `B256` address:
1. `fromString`: Create a new [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from an ambiguous source that may be a `B256` address:

<<< @./snippets/address/utilities-function-1.ts#full{ts:line-numbers}

Expand Down
22 changes: 0 additions & 22 deletions apps/docs/src/guide/types/bech32.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// #region full
import { Address } from 'fuels';

const ADDRESS_BECH32 =
'fuel1elnmzsav56dqnp95sx4e2pckq36cvae9ser44m5zlvgtwxw49fmqd7e42e';
const ADDRESS_B256 =
'0xcfe7b143aca69a0984b481ab950716047586772586475aee82fb10b719d52a76';

const address = new Address(ADDRESS_BECH32);
const address = new Address(ADDRESS_B256);
// #endregion full

console.log('address', address);
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { Address } from 'fuels';

const address = Address.fromRandom();

const addressCloneFromBech = Address.fromString(address.toString());
const addressCloneFromB256 = Address.fromString(address.toB256());
// #endregion full

console.log('addressCloneFromBech', addressCloneFromBech);
console.log('addressCloneFromB256', addressCloneFromB256);
6 changes: 6 additions & 0 deletions apps/docs/src/guide/types/snippets/b256.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// #region addresses-1
const b256 =
'0x9ae5b658754e096e4d681c548daf46354495a437cc61492599e33fc64dcdc30c';
// #endregion addresses-1

console.log('b256', b256);
16 changes: 0 additions & 16 deletions apps/docs/src/guide/types/snippets/bech32.ts

This file was deleted.

27 changes: 2 additions & 25 deletions apps/docs/src/guide/utilities/address-conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

Addresses and varying address formats are commonplace when interacting with decentralized applications. Furthermore, different networks may enforce different address formats.

The Fuel Network uses the [`Bech32`](../types/bech32.md) address format for its interactions, an example of which can be seen below:
The Fuel Network uses the [`Bits256`](../types/bits256.md) address format for its interactions, an example of which can be seen below:

<<< @/../../docs/src/guide/types/snippets/bech32.ts#addresses-1{ts:line-numbers}

> [!NOTE] Note
> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
<<< @/../../docs/src/guide/types/snippets/b256.ts#addresses-1{ts:line-numbers}

However, a hexlified [Bits256](../types/bits256.md) (hex) is another common address format; an example can be seen below:

Expand All @@ -26,26 +23,6 @@ The following [conversion guide](./address-conversion.md#address-conversion) wil

This guide demonstrates how to convert between address formats and Sway Standard Types using helper functions. Native types are wrappers for bytes, and you can perform conversions between them by leveraging these functions and classes.

## From `Bech32` to `b256`

By instantiating an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html), we can validate a `Bech32` address and easily convert it to a `b256`:

<<< @./snippets/address-conversion/bech32-to-b256.ts#conversion-5{ts:line-numbers}

Or, if you'd prefer to use utility functions directly for validation and conversion, you can use `isBech32` and `toB256`:

<<< @./snippets/address-conversion/bech32-to-b256-utilities.ts#conversion-6{ts:line-numbers}

## From `b256` to `Bech32`

In a similar fashion, we have both class functions on the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) and utilities available for `b256` validation and conversion:

<<< @./snippets/address-conversion/b256-to-bech32.ts#conversion-7{ts:line-numbers}

And by using the `isB256` and `toBech32` utilities:

<<< @./snippets/address-conversion/b256-to-bech32-utilities.ts#conversion-8{ts:line-numbers}

## Converting a Contract ID

The Contract `id` property has the [`AbstractAddress`](../types/address.md#abstractaddress-class) type. Therefore, it can be converted using the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class functions such as `toAddress` and `toB256`:
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// #region conversion-2
import type { Bech32Address } from 'fuels';
import type { B256Address } from 'fuels';
import { Address, Provider, Contract } from 'fuels';

import { LOCAL_NETWORK_URL } from '../../../../env';
Expand All @@ -14,10 +14,10 @@ const contractAddress = Address.fromB256(

const contract = new Contract(contractAddress, contractAbi, provider);

const bech32: Bech32Address = contract.id.toAddress();
// fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs
const b256: B256Address = contract.id.toAddress();
// 0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f
// #endregion conversion-2

const expectedBech32 =
'fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs';
console.log('Bech32 address should equal expected', bech32 === expectedBech32);
const expectedB256 =
'0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f';
console.log('B256 address should equal expected', b256 === expectedB256);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// #region conversion-3
import type { Bech32Address, WalletLocked } from 'fuels';
import type { B256Address, WalletLocked } from 'fuels';
import { Address, Provider, Wallet } from 'fuels';

import { LOCAL_NETWORK_URL } from '../../../../env';
Expand All @@ -12,10 +12,10 @@ const address = Address.fromB256(

const wallet: WalletLocked = Wallet.fromAddress(address, provider);

const bech32: Bech32Address = wallet.address.toAddress();
// fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs
const b256: B256Address = wallet.address.toAddress();
// 0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f
// #endregion conversion-3

const expectedBech32 =
'fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs';
console.log('Bech32 address should equal expected', bech32 === expectedBech32);
const expectedB256 =
'0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f';
console.log('b256 address should equal expected', b256 === expectedB256);
2 changes: 1 addition & 1 deletion apps/docs/src/guide/wallets/instantiating-wallets.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ It's possible to instantiate a `WalletUnlocked` from a `WalletLocked`:

You can also instantiate [`WalletLocked`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_account.WalletLocked.html) instances using just the wallet address:

<<< @./snippets/instantiating/from-bech32-address.ts#instantiating-wallets-8{ts:line-numbers}
<<< @./snippets/instantiating/from-b256-address.ts#instantiating-wallets-8{ts:line-numbers}

## Connecting to a Provider

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// #region instantiating-wallets-8
import type { WalletLocked } from 'fuels';
import type { B256Address, WalletLocked } from 'fuels';
import { Wallet } from 'fuels';

const address = `fuel14kjrdcdcp7z4l9xk0pm3cwz9qnjxxd04wx4zgnc3kknslclxzezqyeux5d`;
const address: B256Address = `0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f`;

const wallet: WalletLocked = Wallet.fromAddress(address);
// #endregion instantiating-wallets-8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { WalletLocked, WalletUnlocked } from 'fuels';
import { Wallet } from 'fuels';

const address =
'fuel1fjett54ahnydhklerngqhclzmmkmp6s0xnykns8dwsdpjfg3r2rsfazpw5';
'0x4cb2b5d2bdbcc8dbdbf91cd00be3e2deedb0ea0f34c969c0ed741a1925111a87';
const privateKey =
'0x9deba03f08676716e3a4247797672d8008a5198d183048be65415ef89447b890';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const hashedMessage = hashMessage(message);

const recoveredAddress = Signer.recoverAddress(hashedMessage, signedMessage);
// Example output: Address {
// bech32Address: 'fuel1za0wl90u09c6v88faqkvczu9r927kewvvr0asejv5xmdwtm98w0st7m2s3'
// b256Address: '0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f'
// }
// #endregion signing-1

Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/signer/signer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Signer', () => {
const expectedPrivateKey = '0x5f70feeff1f229e4a95e1056e8b4d80d0b24b565674860cc213bdb07127ce1b1';
const expectedPublicKey =
'0x2f34bc0df4db0ec391792cedb05768832b49b1aa3a2dd8c30054d1af00f67d00b74b7acbbf3087c8e0b1a4c343db50aa471d21f278ff5ce09f07795d541fb47e';
const expectedAddress = 'fuel1785jcs4epy625cmjuv9u269rymmwv6s6q2y9jhnw877nj2j08ehqce3rxf';
const expectedAddress = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e';
const expectedMessage = 'my message';
const expectedB256Address = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e';
const expectedSignedMessage =
Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/wallet/keystore-wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Keystore Wallet', () => {
const privateKey = '0xeac85e732b683119e62fb52ce3b04c0d2f60539cd55af34c731fcdcf802e5ef4';

const address = Address.fromAddressOrString(
'fuel1v77yj3g6xcatrhkcz72m2njx4cxxzgj8yepywz7ylf4fhkpptawqkh3dft'
'0x67bc49451a363ab1ded81795b54e46ae0c6122472642470bc4fa6a9bd8215f5c'
);
const password = '123456';

Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/wallet/wallet-unlocked.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('WalletUnlocked', () => {
const expectedPrivateKey = '0x5f70feeff1f229e4a95e1056e8b4d80d0b24b565674860cc213bdb07127ce1b1';
const expectedPublicKey =
'0x2f34bc0df4db0ec391792cedb05768832b49b1aa3a2dd8c30054d1af00f67d00b74b7acbbf3087c8e0b1a4c343db50aa471d21f278ff5ce09f07795d541fb47e';
const expectedAddress = 'fuel1785jcs4epy625cmjuv9u269rymmwv6s6q2y9jhnw877nj2j08ehqce3rxf';
const expectedAddress = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e';
const expectedMessage = 'my message';
const expectedSignedMessage =
'0x8eeb238db1adea4152644f1cd827b552dfa9ab3f4939718bb45ca476d167c6512a656f4d4c7356bfb9561b14448c230c6e7e4bd781df5ee9e5999faa6495163d';
Expand Down
Loading

0 comments on commit 4ccc628

Please sign in to comment.