Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dart code for working with addresses #796

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
55 changes: 55 additions & 0 deletions docs/develop/dapps/cookbook.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,61 @@ print(address2.to_str(is_user_friendly=True, is_bounceable=True, is_url_safe=Tru
print(address2.to_str(is_user_friendly=False)) # 0:ca6e321c7cce9ecedf0a8ca2492ec8592494aa5fb5ce0387dff96ef6af982a3e
```

</TabItem>
<TabItem value="dart" label="Dart">

Install package with:
```sh
dart pub get tonutils
```

```dart
import 'package:tonutils/tonutils.dart' show InternalAddress;

InternalAddress address1 =
InternalAddress.parse('EQDKbjIcfM6ezt8KjKJJLshZJJSqX7XOA4ff-W72r5gqPrHF');
InternalAddress address2 = InternalAddress.parse(
'0:ca6e321c7cce9ecedf0a8ca2492ec8592494aa5fb5ce0387dff96ef6af982a3e');

// user friendly
print(address1.toString(
isBounceable: true,
isUrlSafe: true,
)); // EQDKbjIcfM6ezt8KjKJJLshZJJSqX7XOA4ff-W72r5gqPrHF
// user friendly
print(address1.toString(
isUrlSafe: false,
)); // EQDKbjIcfM6ezt8KjKJJLshZJJSqX7XOA4ff+W72r5gqPrHF
// HEX
print(
address1.toRawString(),
); // 0:ca6e321c7cce9ecedf0a8ca2492ec8592494aa5fb5ce0387dff96ef6af982a3e

// user friendly
print(address2.toString(
isBounceable: true,
isUrlSafe: true,
)); // EQDKbjIcfM6ezt8KjKJJLshZJJSqX7XOA4ff-W72r5gqPrHF
// HEX
print(
address2.toRawString(),
); // 0:ca6e321c7cce9ecedf0a8ca2492ec8592494aa5fb5ce0387dff96ef6af982a3e

const bool IS_TESTNET_ONLY = true;
// user friendly
print(address1.toString(
isBounceable: true,
isUrlSafe: true,
isTestOnly: IS_TESTNET_ONLY,
)); // kQDKbjIcfM6ezt8KjKJJLshZJJSqX7XOA4ff-W72r5gqPgpP
// user friendly
print(address1.toString(
isBounceable: false,
isUrlSafe: true,
isTestOnly: IS_TESTNET_ONLY,
)); // 0QDKbjIcfM6ezt8KjKJJLshZJJSqX7XOA4ff-W72r5gqPleK
```

</TabItem>
</Tabs>

Expand Down