Libs Integration
Integration
Tonpy has LiteClient only in dev version (tonpy-dev) at the moment
from tonpy import *
test = LiteClient(host="...", port=...,
pubkey_hex="...", timeout=5)
test.get_masterchain_info_ext().last
Tonpy has LiteClient only in dev version (tonpy-dev) at the moment
from tonpy import *
test = LiteClient(host="...", port=...,
pubkey_hex="...", timeout=5)
test.get_masterchain_info_ext().lastimport requests
from pytoniq import LiteBalancer
config = requests.get('LINK_FROM_BOT').json()
provider = LiteBalancer.from_config(config=config, trust_level=2)
await provider.start_up()
result = await client.run_get_method(address='EQBvW8Z5huBkMJYdnfAEM5JqTNkuWX3diqYENkWsIL0XggGG', method='seqno', stack=[])package main
import (
"context"
"fmt"
"log"
"github.com/xssnick/tonutils-go/address"
"github.com/xssnick/tonutils-go/liteclient"
"github.com/xssnick/tonutils-go/ton"
)
func main() {
client := liteclient.NewConnectionPool()
// connect to mainnet lite server
err := client.AddConnection(context.Background(), "IP_FROM_BOT:PORT_FROM_BOT", "BASE64_KEY_FROM_BOT")
if err != nil {
log.Fatalln("connection err: ", err.Error())
return
}
// initialize ton api lite connection wrapper
api := ton.NewAPIClient(client)
// we need fresh block info to run get methods
b, err := api.CurrentMasterchainInfo(context.Background())
if err != nil {
log.Fatalln("get block err:", err.Error())
return
}
/*
We will run such method of contract
cell mult(int a, int b) method_id {
return begin_cell().store_uint(a * b, 64).end_cell();
}
*/
res, err := api.WaitForBlock(b.SeqNo).RunGetMethod(context.Background(), b,
address.MustParseAddr("kQBL2_3lMiyywU17g-or8N7v9hDmPCpttzBPE2isF2GTziky"), "mult", 7, 7)
if err != nil {
log.Fatalln("run get method err:", err.Error())
return
}
val, err := res.MustCell(0).BeginParse().LoadUInt(64)
if err != nil {
println("ERR", err.Error())
return
}
fmt.Printf("parsed result: %d\n", val)
}