Is there the FunC Library that can put Address Type calculated to String data type for smart contract address?

For example, how do you convert
EQATqIQLRMCQ9IyrByFLNvHP_iYr4encZF1M8li9KIOG0fL_
into
0:13a8840b44c090f48cab07214b36f1cffe262be1e9dc645d4cf258bd288386d1
in the FunC?

Jan 4, 2024, 11:38 AM
maybe you can find in func community library ,I saw some address snippet related there
{-
address.fc

This library provide functions for MsgAddressInt type.
-}


(int) address::is_none(slice _addr) inline {
return equal_slices(_addr, addr_none());
}

(int) address::is_hole(slice _addr) inline {
return equal_slices(_addr, HOLE_ADDRESS);
}

(int) address::get_workchain(slice _addr) inline {
(int wc, _) = parse_std_addr(_addr);
return wc;
}

(int) address::get_hashpart(slice _addr) inline {
(_, int hp) = parse_std_addr(_addr);
return hp;
}

(int) address::check_workchain(slice _addr, int _wc) inline {
return _addr.address::get_workchain() == _wc;
}

;; doest trigger error if addr is addr_none
(int) address::check_workchain_nofail(slice _addr, int _wc) inline {
if _addr.address::is_none() {
return true;
}

return _addr.address::check_workchain(_wc);
}

(int) address::check_hashpart(slice _addr, int _hp) inline {
return _addr.address::get_hashpart() == _hp;
}

(slice) address::serialize(int _wc, int _hp) inline {
return begin_cell()
.store_uint(4, 3) ;; 0b100 = addr_std$10 tag; No anycast
.store_int(_wc, 8)
.store_uint(_hp, 256)
.as_slice();
}
this in funcbox::address helper
and this is string helper from open contract ;


{-
strings.func

Provides operations on strings.
-}

(slice) strings::base64url (slice bytes) {
int size = bytes.slice_bits() / 6;
builder result = begin_cell();

repeat (size) {
int code = bytes~load_uint(6);
if (code < 26) {
result~store_uint(65 + code, 8);
}
if ((code >= 26) & (code < 52)) {
result~store_uint(97 + code - 26, 8);
}
if ((code >= 52) & (code < 62)) {
result~store_uint(48 + code - 52, 8);
}
if (code == 62) {
result~store_uint(45, 8);
}
if (code == 63) {
result~store_uint(95, 8);
}
}

size = bytes.slice_bits();
if (size > 0) {
int code = (bytes~load_uint(size)) << (6 - size);
if (code < 26) {
result~store_uint(65 + code, 8);
}
if ((code >= 26) & (code < 52)) {
result~store_uint(97 + code - 26, 8);
}
if ((code >= 52) & (code < 62)) {
result~store_uint(48 + code - 52, 8);
}
if (code == 62) {
result~store_uint(45, 8);
}
if (code == 63) {
result~store_uint(95, 8);
}
}

return result.end_cell().begin_parse();
}
sorry ,hope helps
Jan 4, 2024, 12:20 PM
Thanks! Let us me try out!
https://github.com/ston-fi/funcbox/tree/main/contracts
😂🌊
Jan 4, 2024, 1:57 PM
curl --request GET --url 'https://tonapi.nftscan.com/api/ton/account/own/EQCPxaIxUgHqjK_nyngA0PYqLWcaNyb1CZ9WPB6XGPdunkTZ?show_attribute=true'
From https://docs.nftscan.com/reference/ton/get-all-nfts-by-account
Jan 4, 2024, 3:42 PM
fuckkkk basically we have to put String as Slice DataType and put in here right
is there possible to print Address in String?
Jan 6, 2024, 7:58 AM
You need to store address to slice with

slice my_cs = “EQATqIQLRMCQ9IyrByFLNvHP_iYr4encZF1M8li9KIOG0fL_”a

Than you can use (int wc, int addr) = parse_std_addr(my_cs);

wc and addr are int with base 10. Next you need to convert wc to utf8 char and address to hex and then to utf8 char string.

For hex convertation: (use smth like this)

But don’t forget to zero fill result, because encode_number_to_text(addr, 16) will skip first zeroes in any hex form address (so hex address 000…0001 will be just `1`). You need to pad with zero to 64 symbols.

After success convertation you need to concat slices (wc + “:” + addr) to final string
Jan 6, 2024, 8:09 AM
slice my_cs = "EQATqIQLRMCQ9IyrByFLNvHP_iYr4encZF1M8li9KIOG0fL_"a; works as well.
Jan 6, 2024, 8:13 AM
I am stuck in Tact level that; we only have:

myAddress().asSlice()
Jan 6, 2024, 8:14 AM
And it's possible to avoid slice concatenation by storing everything into single builder.
Jan 6, 2024, 8:14 AM
Sorry, I am confusing right now. To solve this:

- You need to know how Address data type can convert to other data type
- You need to know what is slice, cell, and string data type
Jan 6, 2024, 8:16 AM
All comes simple, when you understand basic of TON (cells / slices).

In Func (actually in TVM, because Func is just sugar with some optimizations to TMV OP codes) there’s no custom types and objects. You operate only with int, slice, cell, builder, tuple (there are other types, but they pro level, you never use them irl).

So all you have is very big integers and bits that are separated into cells/slices which are refer to other cell/slice.

Now as we know basic - answer is simple: there is no such thing as string data type or address data type inside func. You only have bit-representation of such things. For bit representations you use TLB schemes and operate with integers, slices, cells for them.

So “EQATqIQLRMCQ9IyrByFLNvHP_iYr4encZF1M8li9KIOG0fL_”a uses Std address tlb scheme to create slice (all func string literals create slices) of such address. And such tlb schema (actually 2 of them, but you don’t use irl second) is only way to correct store address inside TVM. You actually can create own way of store, but all std functions operate with basic TLB schemes (as `parse_std_addr`).

(int wc, int addr) = parse_std_addr(my_cs); is just “fast bit extractor to two integers with usage of std address tlb scheme” because actually what you need from address is workchain and hex (stateinit hash) part. Devs are using them to calculate access levels or validate something.

So all you need to know is what is TVM, what is cell and how TVM operate with them: https://docs.ton.org/tvm.pdf you can start with 1.1
Jan 6, 2024, 8:56 AM

© 2024 Draquery.com All rights reserved.