Skip to content
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

Deployment error #3

Open
mcnckc opened this issue Sep 30, 2024 · 3 comments
Open

Deployment error #3

mcnckc opened this issue Sep 30, 2024 · 3 comments

Comments

@mcnckc
Copy link

mcnckc commented Sep 30, 2024

I'm trying to deploy contract following provided example

I installed ton.js with yarn add @ton/ton @ton/crypto @ton/core buffer.

Running

import { Cell } from 'ton';

const vanityCode = Cell.fromBoc(
  Buffer.from('te6ccgEBAgEAMgABFP8A9KQT9LzyyAsBAEbT7UTQddch+kCDB9ch0QLQ0wMx+kAwWMcF8ojU1NEB+wTtVA==')
)[0];

with node main.js

results in error:

node_modules\ton-core\dist\boc\cell\serialization.js:160
        throw Error('Invalid magic');
              ^

Error: Invalid magic
    at parseBoc (node_modules\ton-core\dist\boc\cell\serialization.js:160:15)
    at deserializeBoc (node_modules\ton-core\dist\boc\cell\serialization.js:168:15)
    at Cell.fromBoc (node_modules\ton-core\dist\boc\Cell.js:34:51)
    at main.js:3:25

Node.js version: v20.17.0
Yarn version: 1.22.22

How could this be fixed, or how else to achieve succesful deployment?

@bronglil
Copy link

bronglil commented Nov 11, 2024

It seems that the issue stems from the Cell.fromBoc method not recognizing the BOC (Bag of Cells) data due to either an encoding mismatch or a formatting issue with the provided BOC string. To address this effectively, here are a few steps to consider.

First, verify that the BOC string itself (te6ccgEBAgEAMgABFP8A9KQT9LzyyAsBAEbT7UTQddch+kCDB9ch0QLQ0wMx+kAwWMcF8ojU1NEB+wTtVA==) is correct. Even a small typo can cause parsing errors. Additionally, when passing this string to Buffer.from, use the 'base64' encoding explicitly, as shown below, to ensure it’s decoded accurately:

const vanityCode = Cell.fromBoc(Buffer.from('te6ccgEBAgEAMgABFP8A9KQT9LzyyAsBAEbT7UTQddch+kCDB9ch0QLQ0wMx+kAwWMcF8ojU1NEB+wTtVA==', 'base64'))[0];

Updating all dependencies is another critical step; libraries like @ton/ton, @ton/core, @ton/crypto, and buffer are frequently updated, and using the latest versions can resolve compatibility issues. Run yarn upgrade to ensure you have the latest releases. Additionally, compatibility with Node.js v20.17.0 may be a factor here, as some libraries perform best on LTS versions. If updating dependencies doesn’t resolve the issue, try downgrading to Node.js 18, a stable LTS version, then reinstall dependencies with yarn install.

Lastly, if issues persist after trying the above, check the library documentation or GitHub issues section for any recent updates or alternative methods for BOC parsing. With these steps, your script should work as expected, enabling you to deploy the contract successfully.

@mcnckc
Copy link
Author

mcnckc commented Nov 11, 2024

Thank you, explicitly using base64 encoding helped. I suggest to edit this repo's deployment guide accordingly, to make vanity-contract usage easier for not-so experiecned users.

@bronglil
Copy link

You're welcome! I'm glad that using base64 encoding solved the issue. Adding this detail to the deployment guide is a great idea—it would definitely help others who are new to working with BOC data and encoding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants