Git Product home page Git Product logo

ton-sdk-ruby's Introduction

ton-sdk-ruby

Ruby SDK for interaction with TON (The Open Network) blockchain

Installation

Install ton-sdk-ruby:

  • gem install ton-sdk-ruby
⚠️ You might also find it beneficial to make use of the ton-sdk-ruby-smc package, which implements basic wrappers for TON smart contracts (please be aware that ton-sdk-ruby-smc is distributed under the LGPL-3.0 license).

Example

require 'ton-sdk-ruby'

class Ton
  include TonSdkRuby
  
  def main
    # Init address from string
    tf = Address.new("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N")

    # Init and fill the builder
    b = Builder.new
    b.store_uint(200, 30)
    b.store_address(tf)
    b.store_coins(Coins.new(0.0001))

    # End builder and serialize to boc
    bytes = serialize(b.cell)
    base64 = bytes_to_base64(bytes)

    p 'boc in base64 format:', base64, ''

    # Deserialize base64 boc 
    cell = deserialize(base64_to_bytes(base64)).first

    # Parse cell into slice
    cs = cell.parse

    # Load and print values
    p cs.load_uint(30)
    p cs.load_address.to_s
    p cs.load_coins
  end
end

Ton.new.main

License

MIT

Mentions

I would like to thank cryshado for their valuable advice and help in developing this library.

ton-sdk-ruby's People

Contributors

nerzh avatar

Stargazers

 avatar Dima avatar maelus avatar Kirill Shevchenko avatar  avatar

Watchers

 avatar Dima avatar  avatar

ton-sdk-ruby's Issues

Workchain isn't parsed correctly

The workchain info is lost when round-tripping from an encoded address:

irb(main):023> TonSdkRuby::Address.new('Ef8w0Zxb55PR2HtfD793UTXggGNNZJcTKh3bh4u4X-nMWGK-')
=>
#<TonSdkRuby::Address:0x00007f8cf0f1de00
 @bounceable=true,
 @hash=[48, 209, 156, 91, 231, 147, 209, 216, 123, 95, 15, 191, 119, 81, 53, 224, 128, 99, 77, 100, 151, 19, 42, 29, 219, 135, 139, 184, 95, 233, 204, 88],
 @test_only=false,
 @workchain=0>
irb(main):024> TonSdkRuby::Address.new('Ef8w0Zxb55PR2HtfD793UTXggGNNZJcTKh3bh4u4X-nMWGK-').to_s
=> "EQAw0Zxb55PR2HtfD793UTXggGNNZJcTKh3bh4u4X-nMWJ32"
irb(main):025>

I.e. addresses starting with Ef are in the -1 workchain.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.