xssnick / tonutils-go Goto Github PK
View Code? Open in Web Editor NEWTON SDK Library in pure Golang for interacting with The Open Network ecosystem using native protocols, such as ADNL, RLDP and etc.
License: Apache License 2.0
TON SDK Library in pure Golang for interacting with The Open Network ecosystem using native protocols, such as ADNL, RLDP and etc.
License: Apache License 2.0
func getWallet(api *ton.APIClient) *wallet.Wallet {
words := strings.Split("birth pattern then forest walnut then phrase walnut fan pumpkin pattern then cluster blossom verify then forest velvet pond fiction pattern collect then then", " ")
w, err := wallet.FromSeed(api, words, wallet.V3)
if err != nil {
panic(err)
}
return w
}
any correct flow for this ?
How do I get user wallet without user insert this seed
When I try to send a transaction using wallet.SendWaitTransaction, the contract gets deployed. When I do it second time, it tries to re-deploy the contract, which results in "Something happened but we don't understand what.", but no coins get actually sent for some reason.
You can see it here: https://testnet.tonviewer.com/kQDdo8y5BSM2tsDB29FxRsQ1TC5-523KZ5xgbpPjdDwHIhgE
More examples = easier to understand.
The task is to add more real world examples, DEX Swap (dedust for example), NFT put on sale, DNS auction, NFT sale buy and etc. For the contract message serialization please use struct with tlb
tags, for the cleaner cell building (example).
If you want to add an example, leave a comment here with a small description about what you are going to add, i'll approve it with (👍) and you can start. This task can be done by many developers (each one can add own example).
When you are done, just make PR to master branch, and leave a comment here.
It would be great to have raw.sendMessageReturnHash implemented in addition to raw.sendMessage.
My idea is that it would bring more info for tx flow, like getting something similar to txid on send, so we can generate a link for different explorers.
RaptorQ package (used for forward error correction encoding) is used by RLDP protocol, which is one of the building blocks of TON communication, it is used by such components as Storage, Proxy, Nodes. Current implementation is not so efficient as it could be, for example maps usage can be replaced to arrays/slices.
The task is to optimize raptorq+discmath packages, cover them with unit tests and add benchmarks. Please don't use CGO or external libraries.
You could start from benchmarks to understand current behaviour and speed. Usage example can be found in rldp package.
If you want to take the task, leave a comment here (time estimation will be a plus). When you are done, just make PR to dev-v19
branch, and leave a comment here.
here is my code
var messages []*wallet.Message
messages = append(messages, &wallet.Message{
Mode: 1,
InternalMessage: &tlb.InternalMessage{
Bounce: false,
DstAddr: addr,
Amount: amount,
Body: comment,
},
})
// send tx and wait for it
tx, block, err := w.SendManyWaitTransaction(context.Background(), messages)
if err != nil {
global.LOG.Sugar().Error("Transfer err:", err.Error())
return err
}
An error occurred when I tried to parse out the address through the mnemonic phrase and obtain the address balance.
I tried using the mainnet configuration file, and errors occurred with the specified node.
2024/01/31 22:11:19 GetBalance err: failed to get account state: lite server error, code 651: too big masterchain block seqno exit status 1
This is why?
Hey there,
is it possible to add support for V3R1 wallets? now only V3R2 implemented
tonutils-go/ton/wallet/address.go
Lines 57 to 76 in d9f8c2c
` token := jetton.NewJettonMasterClient(api, address.MustParseAddr(contractAddrStr))
// find our jetton wallet
tokenWallet, err := token.GetJettonWallet(context.Background(), wallet.WalletAddress())
if err != nil {
return nil, err
}
comment, err := pkgTonWallet.CreateCommentCell(memo)
if err != nil {
return nil, err
}
transferPayload, err := tokenWallet.BuildTransferPayloadV2(address.MustParseAddr(toStr), address.MustParseAddr(responseToStr), tlb.MustFromNano(value, tokenDecimal), tlb.MustFromTON("0.000000001"), comment, nil)
if err != nil {
return nil, err
}
unsignedTx = pkgTonWallet.SimpleMessage(tokenWallet.Address(), tlb.MustFromTON("0.05"), transferPayload)
`
构建交易,发现excess地址永远是jetton收款地址(to),如何将excess设置成发送方地址(from)?
Some litenodes were updated in testnet yesterday and now we get this error on GetBlockShardsInfo():
v.1.8.9
failed to check proof: should have 2 roots
v1.9.0 return timeout
Could you please take a look?
client := liteclient.NewClient()
err := client.Connect(context.Background(),
"67.207.74.182:4924",
"peJTw/arlRfssgTuf9BMypJzqOi7SXEqSPSWiEw2U1M=")
if err != nil {
panic(err)
}
api := ton.NewAPIClient(client)
block, err := api.GetBlockInfo(context.Background())
if err != nil {
Log.Fatalln("get block err:", err.Error())
return
}
_, err = api.RunGetMethod(context.Background(), block, address.MustParseAddr("EQCunKWfEsKkdhSXZAEWDpck8rSvcIjV_V_6CBA6UsI0XRBu"), "get_nft_data")
if err != nil {
Log.Errorf("run get method err: %s", err.Error())
return
}
panic: too small slice for this size goroutine 1 [running]: github.com/xssnick/tonutils-go/tvm/cell.(*Builder).MustStoreSlice(...) .../github.com/xssnick/[email protected]/tvm/cell/builder.go:134 github.com/xssnick/tonutils-go/ton.(*APIClient).RunGetMethod(0xc000119f40, {0x70aec8, 0xc000016050}, 0xc000194140, 0xc0001820a0, {0x6d1222, 0xc}, {0x0, 0x0, 0x0}) .../github.com/xssnick/[email protected]/ton/api.go:253 +0x1745 main.main() .../test/lite-client.go:29 +0x205
> runmethod EQCunKWfEsKkdhSXZAEWDpck8rSvcIjV_V_6CBA6UsI0XRBu get_nft_data
[ 3][t 1][2022-04-29 00:52:24.707931189][lite-client.cpp:1324][!testnode] requesting remote get-method execution for 0:AE9CA59F12C2A47614976401160E9724F2B4AF7088D5FD5FFA08103A52C2345D with respect to (-1,8000000000000000,20168059):A348D3D666FF09B2FAEC3F06419F7D9CA9F1B6CC4FF62D0E865C8040D05994CB:F14E06284BC7A8F525EC1BE4210A7D56EE9FECF58AB8466BB6F48D2FAB75D489 to run method get_nft_data with 0 parameters
[ 3][t 2][2022-04-29 00:52:24.767547252][lite-client.cpp:1998][!testnode] got (partial) account state (637 bytes) with mode=31 for 0:AE9CA59F12C2A47614976401160E9724F2B4AF7088D5FD5FFA08103A52C2345D with respect to blocks (-1,8000000000000000,20168059):A348D3D666FF09B2FAEC3F06419F7D9CA9F1B6CC4FF62D0E865C8040D05994CB:F14E06284BC7A8F525EC1BE4210A7D56EE9FECF58AB8466BB6F48D2FAB75D489 and (0,8000000000000000,25326017):6FEB8CDE0C810A3CBC4FEEC5685103FD5FCEF48B7DDCEAF320668D153369796D:6DA394AC82E92EAD9F9770796F9260CB5B3C2CD2A91AEA2DEB075C5CC8AA6BF9
[ 3][t 2][2022-04-29 00:52:24.767826707][lite-client.cpp:2095][!testnode] starting VM to run method `get_nft_data` (102351) of smart contract 0:AE9CA59F12C2A47614976401160E9724F2B4AF7088D5FD5FFA08103A52C2345D
arguments: [ 102351 ]
result: [ -1 0 CS{Cell{0295000000000000000080051eec1b065126304253957c14810c949f9902ec722d1aa47adb690497b32f7cd0027e457611181313ddf9812a3ef5d3b9dcf80c7f1bdb9ff8d57fc9e74a3ce93c46} bits: 64..331; refs: 0..0} CS{Cell{0295000000000000000080051eec1b065126304253957c14810c949f9902ec722d1aa47adb690497b32f7cd0027e457611181313ddf9812a3ef5d3b9dcf80c7f1bdb9ff8d57fc9e74a3ce93c46} bits: 331..598; refs: 0..0} C{62EDF0EE80EF8562B380870C568CB4965EBED8FFF0308548C263FB9FAD023020} ]
remote result (not to be trusted): [ -1 0 CS{Cell{0295000000000000000080051eec1b065126304253957c14810c949f9902ec722d1aa47adb690497b32f7cd0027e457611181313ddf9812a3ef5d3b9dcf80c7f1bdb9ff8d57fc9e74a3ce93c46} bits: 64..331; refs: 0..0} CS{Cell{0295000000000000000080051eec1b065126304253957c14810c949f9902ec722d1aa47adb690497b32f7cd0027e457611181313ddf9812a3ef5d3b9dcf80c7f1bdb9ff8d57fc9e74a3ce93c46} bits: 331..598; refs: 0..0} C{62EDF0EE80EF8562B380870C568CB4965EBED8FFF0308548C263FB9FAD023020} ]
[ 3][t 2][2022-04-29 00:52:24.767973694][lite-client.cpp:1225][!testnode] caching cell 62EDF0EE80EF8562B380870C568CB4965EBED8FFF0308548C263FB9FAD023020
{"time":"2024-06-11T00:45:29.191189+08:00","level":"ERROR","msg":"error sending USDT","error":"failed to run get_wallet_address method: contract exit code: -256 (contract is not initialized)"}
failed to run get_wallet_address method: contract exit code: -256 (contract is not initialized
seeds := strings.Split(mnemonic, " ")
w, err := wallet.FromSeed(api, seeds, wallet.V4R2)
if err != nil {
return nil, err
}
destAddr, err := address.ParseAddr(to)
if err != nil {
return nil, err
}
token := jetton.NewJettonMasterClient(c.api, address.MustParseAddr(contract.ContractAddress))
// find our jetton wallet
// where the error happens and I am not sure why?
// it used to work :(
tokenWallet, err := token.GetJettonWallet(ctx, w.WalletAddress())
if err != nil {
return nil, err
}
tokenBalance, err := tokenWallet.GetBalance(ctx)
if err != nil {
return nil, err
}
amountTokens, err := tlb.FromDecimal(amount, 0)
if err != nil {
return nil, err
}
if tokenBalance.Int64() < amountTokens.Nano().Int64() {
slog.Warn("token balance", "balance", tokenBalance.Int64(), "amount", amountTokens.Nano().Int64())
return nil, ErrHotWalletInsufficientBalance
}
comment, err := wallet.CreateCommentCell(reqID)
if err != nil {
return nil, err
}
// address of receiver's wallet (not token wallet, just usual)
transferPayload, err := tokenWallet.BuildTransferPayloadV2(destAddr, destAddr, amountTokens, tlb.ZeroCoins, comment, nil)
if err != nil {
return nil, err
}
msg := wallet.SimpleMessage(tokenWallet.Address(), amountTokens, transferPayload)
tx, _, err := w.SendWaitTransaction(ctx, msg)
if err != nil {
return nil, err
}
return tx, nil
when transfer jetton, i noticed the jetton amount and comment has been included in transferPayload then included into message body, my purpose is to parse tx from ListTransactions, this sdk is not supported to get jetton amount and comment, so i try to parse message body to find out ,i can get the message body by 'body:=tx.IO.In.AsInternal().Body', but how to parse the body to readable text?
Hi all, I have a question about jetton message.
If I have a cell that contains lots of additional payload, when I use BuildTransferPayloadV2
, cell will be parsed and every data will be appended to the msg_body.
Line 558 in c0b96b2
It may caused cell overflow
error. So Im confused why not use store_ref()
to store cell? or maybe I have a wrong thinking?
Thanks for everyone's answer.
Hi! In a nutshell, i'm building an app that detect transactions from specific addresses set by user so i need to compare user-friendly addresses (that user send to app) with raw addresses from subscription channel:
senderUFAddr := "sender-user-friendly-address"
go api.SubscribeOnTransactions(context.Background(), receiverAddress, lastProcessedLT, transactions)
for tx := range transactions {
if tx.IO.In == nil || tx.IO.In.Msg == nil {
fmt.Println("not an in message")
continue
}
internalMessage, ok := tx.IO.In.Msg.(*tlb.InternalMessage)
if !ok {
fmt.Println("not an internal message")
continue
}
senderRawAddr := internalMessage.SrcAddr.String()
lastProcessedLT = tx.LT
}
How can i do this comparison with tonutils or i have to implement it on my own?
I am trying to use ConnectionPool
for accessing validator-engine-console with more or less the following code:
tl.Register(ValidatorStats{}, "engine.validator.getStats = engine.validator.Stats")
...
client := liteclient.NewConnectionPool()
// Read key files etc...
err = client.AddConnection(
context.Background(),
"NODE_IP:PORT",
serverKeyPubB64,
clinetKeyFull,
)
if err != nil {
panic(err)
}
fmt.Println("Connected to server")
var resp tl.Serializable
err = client.QueryADNL(context.Background(), ValidatorStats{}, &resp)
if err != nil {
panic(err)
}
...
What I am getting in response is engine.validator.ControlQueryError
with Code:602 Message:forbidden
.
Running validator-engine-console
against the same host with the same keys works fine.
So my question is if it is possible to use the library to access validator-engine-console, or is it strictly specific to lite server? If so if you could point me to some resources to understand the specificity I would be very grateful (I am not proficient enough in c++ to figure it out quickly from Ton codebase).
Hello. I get error Failed to parse payload: recursive reference of cells
when deserializing stateinit from mytonwallet (ton connect).
Error occurs on the call cell.FromBOC
.
I believe this is a bug, because I was able to successfully parse this stateinit using tongo library as shown in the example.
Tonutils version: v1.8.9
Example:
package main
import (
"encoding/base64"
"fmt"
"log"
"github.com/tonkeeper/tongo/tonconnect"
"github.com/xssnick/tonutils-go/tvm/cell"
)
func main() {
// address
// UQBe7yULTjbWZszDK2d8LOePumy9ZtGzwQgrXXfqjR1yM2fy
// stateInit from mytonwallet
stateInit := "te6ccsECFgEAAwQAAAAABQAwAD0AQgDEAMsBAwE9AXYBewGAAa8BtAG/AcQByQHYAecCCAJ/AsYCATQCAQBRAAAAACmpoxf4lk0qBZddWkKNjjqmudjY6QDlccYne0gS9zCGDH3x2kABFP8A9KQT9LzyyAsDAgEgCQQE+PKDCNcYINMf0x/THwL4I7vyZO1E0NMf0x/T//QE0VFDuvKhUVG68qIF+QFUEGT5EPKj+AAkpMjLH1JAyx9SMMv/UhD0AMntVPgPAdMHIcAAn2xRkyDXSpbTB9QC+wDoMOAhwAHjACHAAuMAAcADkTDjDQOkyMsfEssfy/8IBwYFAAr0AMntVABsgQEI1xj6ANM/MFIkgQEI9Fnyp4IQZHN0cnB0gBjIywXLAlAFzxZQA/oCE8tqyx8Syz/Jc/sAAHCBAQjXGPoA0z/IVCBHgQEI9FHyp4IQbm90ZXB0gBjIywXLAlAGzxZQBPoCFMtqEssfyz/Jc/sAAgBu0gf6ANTUIvkABcjKBxXL/8nQd3SAGMjLBcsCIs8WUAX6AhTLaxLMzMlz+wDIQBSBAQj0UfKnAgIBSBMKAgEgDAsAWb0kK29qJoQICga5D6AhhHDUCAhHpJN9KZEM5pA+n/mDeBKAG3gQFImHFZ8xhAIBIA4NABG4yX7UTQ1wsfgCAVgSDwIBIBEQABmvHfaiaEAQa5DrhY/AABmtznaiaEAga5Drhf/AAD2ynftRNCBAUDXIfQEMALIygfL/8nQAYEBCPQKb6ExgAubQAdDTAyFxsJJfBOAi10nBIJJfBOAC0x8hghBwbHVnvSKCEGRzdHK9sJJfBeAD+kAwIPpEAcjKB8v/ydDtRNCBAUDXIfQEMFyBAQj0Cm+hMbOSXwfgBdM/yCWCEHBsdWe6kjgw4w0DghBkc3RyupJfBuMNFRQAilAEgQEI9Fkw7UTQgQFA1yDIAc8W9ADJ7VQBcrCOI4IQZHN0coMesXCAGFAFywVQA88WI/oCE8tqyx/LP8mAQPsAkl8D4gB4AfoA9AQw+CdvIjBQCqEhvvLgUIIQcGx1Z4MesXCAGFAEywUmzxZY+gIZ9ADLaRfLH1Jgyz8gyYBA+wAGdYbenA=="
_, err := tonconnect.ParseStateInit(stateInit)
if err != nil {
log.Fatal(err)
}
// ok
fmt.Println("parsed 1")
stateInitBytes, err := base64.StdEncoding.DecodeString(stateInit)
if err != nil {
log.Fatal(err)
}
_, err = cell.FromBOC(stateInitBytes)
if err != nil {
log.Fatal(err) // failed to parse payload: recursive reference of cells
}
fmt.Println("parsed 2")
}
Hi,
How can we get all transaction fees like it declared in tonlib_api.tl ?
raw.transaction address:accountAddress utime:int53 data:bytes transaction_id:internal.transactionId fee:int64 storage_fee:int64 other_fee:int64 in_msg:raw.message out_msgs:vector = raw.Transaction;
While using tonlib client we always can get fee:int64 storage_fee:int64 other_fee:int64, but tonutils lib provides only TotalFees or I didn't find...
Could you please clarify this moment for me?
How to pack multiple Jetton transfers into single external message using a highload wallet? Didn't find any example
To be more clear, I'm trying to implement this one: https://docs.ton.org/develop/dapps/asset-processing/jettons#withdrawals-made-from-deposits
Thanks in advance.
how to add messge in jetton tansfer?
I'm trying to load history transaction of an wallet, but always get this error:
send err: lite server error, code -400: cannot load block (0,8000000000000000,40278934):ED46C7BCB4EF18DD435C2F17A55DE395B4F8E49E3AF6BCCF856E4050DF317D5D:51BC46484CF32A99E74B8A5FD54A589EE3FC68E452CFA5C5538FB5C38E757261 with specified transaction: not in db
Anyone know how to fix it? Does that mean all lite servers are down?
Thanks.
I just use the example code to test this feature:
https://github.com/xssnick/tonutils-go/blob/master/example/account-state/main.go
Hey Nick, I'm new to Ton Blockchain. Can I ask have you implemented a method to get all transactions of an exact block yet? With go-ethereum it looks like : block, err := client.BlockByNumber(context.Background(), big.NewInt(3000000)).
Hope I will get your answer soon :) thank you very much for this library.
Hi!
In readme
file, Merkle proofs automatic validation
is not checked.
But I see Merkle proofs
are checked in the features.
How can I make sure that Merkle proofs work on my integration?
Beat Regards.
Hey! Could you please check, current example is not work. Probably this happened because multiple shard became alive in mainnet. I found out that error appears in this switch case with zero value in ab variable. Could you please research it and maybe adding another case to this switch case would fix the problem? And then I switched mode to ProofCheckPolicyUnsafe, checks was skipped and everything works well. Is it safe to use ProofCheckPolicyUnsafe?
How to parse the map in Tact using Golang when I call get method
ts script:
async getMap(provider: ContractProvider) {
let builder = new TupleBuilder();
let source = (await provider.get('map', builder.build())).stack;
let result = Dictionary.loadDirect(Dictionary.Keys.BigInt(257), Dictionary.Values.BigInt(257), source.readCellOpt());
return result;
}
build message err: get seqno err: adnl request timeout, node 164.68.101.206:52995 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.