Bonfida / token-vesting

A Vesting Contract for the Solana Blockchain
https://vesting.bonfida.org/
Other
257 stars 171 forks source link

Error processing Instruction 0: custom program error: 0x0 #25

Closed syedshahzebhasnain closed 2 years ago

syedshahzebhasnain commented 2 years ago

Hi, I am trying to run the JS linear vesting program from the samples. I am also using the deployed contract on devnet but i keep getting this error :

`Seed: 4949774028594395608608647271452266710364072223473245592442783631 Vesting contract account pubkey: HjJh7r5KgzNjePsmXuyqnCFCgoX7oCigCDZ5PvatWte1 contract ID: 4Wrnvad4AqKwUtnLu7JujW3TSEtKmwyGVTrMH9oUrjTS Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0 Program Hj9R6bEfrULLNrApMsKCEaHR9QJ2JgRtM381xgYcjFmQ invoke [1] Program log: Entrypoint Program log: Beginning processing Program log: Error: Invalid instruction! Program Hj9R6bEfrULLNrApMsKCEaHR9QJ2JgRtM381xgYcjFmQ consumed 1540 of 200000 compute units Program Hj9R6bEfrULLNrApMsKCEaHR9QJ2JgRtM381xgYcjFmQ failed: custom program error: 0x0 /Users/x/work/y/node_modules/@solana/web3.js/lib/index.cjs.js:6591 throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs); ^

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0 at Connection.sendEncodedTransaction (/Users/x/work/y/node_modules/@solana/web3.js/lib/index.cjs.js:6591:13) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Connection.sendRawTransaction (/Users/x/work/y/node_modules/@solana/web3.js/lib/index.cjs.js:6550:20) at async Connection.sendTransaction (/Users/x/work/y/node_modules/@solana/web3.js/lib/index.cjs.js:6540:12) { logs: [ 'Program Hj9R6bEfrULLNrApMsKCEaHR9QJ2JgRtM381xgYcjFmQ invoke [1]', 'Program log: Entrypoint', 'Program log: Beginning processing', 'Program log: Error: Invalid instruction!', 'Program Hj9R6bEfrULLNrApMsKCEaHR9QJ2JgRtM381xgYcjFmQ consumed 1540 of 200000 compute units', 'Program Hj9R6bEfrULLNrApMsKCEaHR9QJ2JgRtM381xgYcjFmQ failed: custom program error: 0x0' ] }`

The owner and destination wallets are funded I tried running through the CLI but still getting the same error.

Any help would be highly appreciated.

dr497 commented 2 years ago

Mind sharing your code or a tx id?

syedshahzebhasnain commented 2 years ago

Thanks for the prompt reply. I dont see any transaction id. The code is below :

`import { Connection, PublicKey, Keypair } from '@solana/web3.js'; import fs from 'fs'; import { Numberu64, generateRandomSeed, signTransactionInstructions, } from './utils'; import { Schedule } from './state'; import { create, TOKEN_VESTING_PROGRAM_ID } from './main';

/*

/* Path to your wallet / const WALLET_PATH = './keys/id_owner.json'; const DEST_WALLET_PATH = './keys/id_dest.json'

const wallet = getWallet(WALLET_PATH); console.log(Main wallet public key: ${wallet.publicKey}); const destWallet = getWallet(DEST_WALLET_PATH)

//Keypair.fromSecretKey( // new Uint8Array(JSON.parse(fs.readFileSync(WALLET_PATH).toString())), //keyUint8 //);

/* There are better way to generate an array of dates but be careful as it's irreversible / const DATES = [ new Date(2022, 12), new Date(2023, 1), new Date(2023, 2), new Date(2023, 3), new Date(2023, 4), new Date(2023, 5), new Date(2023, 6), new Date(2023, 7), new Date(2023, 8), new Date(2023, 9), new Date(2023, 10), new Date(2023, 11), new Date(2024, 12), new Date(2024, 2), new Date(2024, 3), new Date(2024, 4), new Date(2024, 5), new Date(2024, 6), new Date(2024, 7), new Date(2024, 8), new Date(2024, 9), new Date(2024, 10), new Date(2024, 11), new Date(2024, 12), ];

/* Info about the desintation / const DESTINATION_OWNER = destWallet.publicKey; const DESTINATION_TOKEN_ACCOUNT = new PublicKey('CXduGjYbZFRm7m3jKf61LoNKopfr3kFYgGZdUunc7LLQ');

/* Token info / const MINT = new PublicKey("EkK4MJuTffX5J6bZpU47QbXjKUqfwqoLHp9hA8x2fmUa"); const DECIMALS = 9;

/* Info about the source / const SOURCE_TOKEN_ACCOUNT = new PublicKey('7bsVL6j59stfSsX1RNjfEYb3ogubEwPeFJ8f1NE75tRd');

/* Amount to give per schedule / const AMOUNT_PER_SCHEDULE = 1;

/* Your RPC connection / const connection = new Connection('https://api.devnet.solana.com');

/* Do some checks before sending the tokens / const checks = async () => { const tokenInfo = await connection.getParsedAccountInfo( DESTINATION_TOKEN_ACCOUNT, ); console.log(tokenInfo) // @ts-ignore const parsed = tokenInfo.value.data.parsed; if (parsed.info.mint !== MINT.toBase58()) { throw new Error('Invalid mint'); } if (parsed.info.owner !== DESTINATION_OWNER.toBase58()) { throw new Error('Invalid owner'); } if (parsed.info.tokenAmount.decimals !== DECIMALS) { throw new Error('Invalid decimals'); } };

/ Function that locks the tokens */ const lock = async () => { await checks(); const schedules: Schedule[] = []; for (let date of DATES) { schedules.push( new Schedule( /* Has to be in seconds / new Numberu64(date.getTime() / 1_000), / Don't forget to add decimals / new Numberu64(AMOUNT_PER_SCHEDULE Math.pow(10, DECIMALS)), ), ); } const seed = generateRandomSeed();

console.log(Seed: ${seed});

const instruction = await create( connection, TOKEN_VESTING_PROGRAM_ID, Buffer.from(seed), wallet.publicKey, wallet.publicKey, SOURCE_TOKEN_ACCOUNT, DESTINATION_TOKEN_ACCOUNT, MINT, schedules );

const tx = await signTransactionInstructions( connection, [wallet], wallet.publicKey, instruction, );

console.log(Transaction: ${tx}); };

lock(); function getWallet(path:string) { return Keypair.fromSecretKey( new Uint8Array(JSON.parse(fs.readFileSync(path).toString())) ) } `

DEGA-hoangmai commented 2 years ago

I have the same issue. Do you guys have any solutions? Thank you.

dr497 commented 2 years ago

Looks like you don't have SOL in your wallet

DEGA-hoangmai commented 2 years ago

@dr497 Thank you for responding. I have 10 sols in the source wallet and 3 sols in the target wallet, and the payer should be source wallet.

syedshahzebhasnain commented 2 years ago

@dr497 I have atleast 5 SOL in the source wallet and 3 in the destination wallet.

DEGA-hoangmai commented 2 years ago

@syedshahzebhasnain did you figure out?

syedshahzebhasnain commented 2 years ago

@DEGA-hoangmai , no i wasnt able to figure it out. I deployed my own version and used that.

chunghyunp commented 2 years ago

having same issue :(

DEGA-hoangmai commented 2 years ago

@DEGA-hoangmai , no i wasnt able to figure it out. I deployed my own version and used that.

can you share your version or any way to use js to connect to your dapp? I want to learn more. Much appreciate

syedshahzebhasnain commented 2 years ago

@DEGA-hoangmai, Looks like theres an update on the https://github.com/Bonfida/token-vesting/blob/master/js/README.md with the updated contract address. Try that out first.

Else you could always follow the steps in https://github.com/Bonfida/token-vesting/tree/master/cli to deploy your own contract and then update the TOKEN_VESTING_PROGRAM_ID on https://github.com/Bonfida/token-vesting/blob/master/js/src/main.ts to your deployed contract address.