xssnick / tonutils-go

TON SDK Library in pure Golang for interacting with The Open Network ecosystem using native protocols, such as ADNL, RLDP and etc.
Apache License 2.0
464 stars 95 forks source link

Issue sending JETTON USDT - "failed to run get_wallet_address method: contract exit code: -256 (contract is not initialized)" #201

Closed metarsit closed 2 months ago

metarsit commented 2 months ago

Context

Logs

{"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)"}

Error Message

failed to run get_wallet_address method: contract exit code: -256 (contract is not initialized

Code

    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
xssnick commented 2 months ago

Hi, contract not initialized error means that this contract is not exist, it looks like you are using wrong jetton master address or wrong network

metarsit commented 2 months ago

You are right. Closer inspection, I was using Prod contract on Test net lololol! Thanks and sorry for false alarm.