-
Notifications
You must be signed in to change notification settings - Fork 1
fill how to find jetton wallet page #595
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
eb6a2d4
Initial commit
Karkarmath af5f638
Merge branch 'main' into how-to-find-jetton-wallet
Karkarmath a949b5b
Formater
Karkarmath 8a28d34
Merge branch 'main' into how-to-find-jetton-wallet
Karkarmath 4451c99
Improvements after Philip review
Karkarmath c8fdd22
Merge branch 'how-to-find-jetton-wallet' of github.com:tact-lang/mint…
Karkarmath 8eeb6ab
review
f2aabb4
review: change the image
3a83344
Impro
Karkarmath 850c908
Merge branch 'how-to-find-jetton-wallet' of github.com:tact-lang/mint…
Karkarmath 7c9560b
Formatter
Karkarmath 7fece76
Merge branch 'main' into how-to-find-jetton-wallet
Karkarmath 54a0659
Update standard/tokens/jettons/how-to-find.mdx
anton-trunov d239eee
Fixes
Karkarmath 559096c
Merge branch 'how-to-find-jetton-wallet' of github.com:tact-lang/mint…
Karkarmath b0dfbb0
Formater
Karkarmath d5376ef
Merge branch 'main' into how-to-find-jetton-wallet
Karkarmath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,90 @@ | ||
--- | ||
title: "How to find" | ||
title: "How to find Jetton wallet" | ||
--- | ||
|
||
Stub | ||
Some application may want to be able to discover their or other contract wallets for some specific Jetton Master. | ||
For instance some contract may want to obtain and store its jetton wallet for some Jetton to handle transfer notifications from it in specific way. | ||
|
||
To compute the address of a Jetton wallet from the address of its owner (a regular user wallet), | ||
Karkarmath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
the Jetton master contract provides the `get_wallet_address (slice owner_address)` method. | ||
|
||
```typescript | ||
import { TonClient, Address, beginCell, TupleItemSlice } from "@ton/ton"; | ||
anton-trunov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
async function main() { | ||
const client = new TonClient({ | ||
endpoint: "https://toncenter.com/api/v2/jsonRPC", | ||
}); | ||
const jettonMasterAddress = Address.parse( | ||
"put the Jetton master address in any format", | ||
); | ||
const walletAddress = Address.parse("put owner's address in any format"); | ||
const walletAddressCell = beginCell().storeAddress(walletAddress).endCell(); | ||
// forming the required type for the stack | ||
const el: TupleItemSlice = { | ||
type: "slice", | ||
cell: walletAddressCell, | ||
}; | ||
// call the get method with a non-empty stack | ||
const data = await client.runMethod( | ||
jettonMasterAddress, | ||
"get_wallet_address", | ||
[el], | ||
); | ||
// get the Jetton wallet address | ||
console.log(data.stack.readAddress()); | ||
} | ||
|
||
void main(); | ||
``` | ||
|
||
Or if you are sure about structure of Jetton wallet's initial persistent storage and know its code, you | ||
can also manually create `StateInit` of the Jetton wallet and thus calculate its address. | ||
|
||
<Warning> | ||
Use this method with great care, as the c4 of Jetton wallet contracts is not specified. | ||
</Warning> | ||
|
||
```typescript | ||
import { | ||
Address, | ||
Cell, | ||
beginCell, | ||
contractAddress, | ||
StateInit, | ||
} from "@ton/core"; | ||
|
||
// let's choose Thether USDT as an example | ||
|
||
const jettonwalletcode = Cell.fromHex( | ||
"b5ee9c72010101010023000842028f452d7a4dfd74066b682365177259ed05734435be76b5fd4bd5d8af2b7c3d68", | ||
); | ||
|
||
const masterAddress = Address.parse( | ||
"0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe", | ||
); | ||
const ownerAddress = Address.parse("an address in any format"); | ||
const jettonwalletdata = beginCell() | ||
.storeAddress(ownerAddress) | ||
.storeAddress(masterAddress) | ||
.storeVarUint(0, 16) // the initial value is always zero | ||
.endCell(); | ||
|
||
const jettonWalletStateInit: StateInit = { | ||
code: jettonwalletcode, | ||
data: jettonwalletdata, | ||
}; | ||
|
||
const BASECHAIN = 0; // All Jetton wallet contracts are located in Basechain by default | ||
const jettonWalletAddress = contractAddress(BASECHAIN, jettonWalletStateInit); | ||
|
||
console.log(jettonWalletAddress.toString()); | ||
``` | ||
|
||
There are also various web services that allow you to call contract's get methods without writing any code. | ||
For example, let's inspect the [Tether USD](https://tonviewer.com/EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs?section=method) master | ||
contract page on Tonviewer. Inserting owner's address in any format and executing the get method, you obtain the Jetton wallet address. | ||
Karkarmath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
 | ||
|
||
Finally, you can use [built-in APIs](/ecosystem/rpc/toncenter). | ||
anton-trunov marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.