Loading...
If you are developing the solana program and passing the integer as argument in the function called by program.rpc then you may be getting the error like
TypeError: src.toArrayLike is not a function
at BNLayout.encode (/home/ganesh/Documents/Blockchain/solana/myproject/node_modules/@project-serum/borsh/dist/lib/index.js:37:37)
at Structure.encode (/home/ganesh/Documents/Blockchain/solana/myproject/node_modules/buffer-layout/lib/Layout.js:1263:26)
at BorshInstructionCoder._encode (/home/ganesh/Documents/Blockchain/solana/myproject/node_modules/@project-serum/anchor/dist/cjs/coder/borsh/instruction.js:91:28)
at BorshInstructionCoder.encode (/home/ganesh/Documents/Blockchain/solana/myproject/node_modules/@project-serum/anchor/dist/cjs/coder/borsh/instruction.js:76:21)
at /home/ganesh/Documents/Blockchain/solana/myproject/node_modules/@project-serum/anchor/dist/cjs/program/namespace/index.js:41:100
at ix (/home/ganesh/Documents/Blockchain/solana/myproject/node_modules/@project-serum/anchor/dist/cjs/program/namespace/instruction.js:50:23)
at txFn (/home/ganesh/Documents/Blockchain/solana/myproject/node_modules/@project-serum/anchor/dist/cjs/program/namespace/transaction.js:16:20)
at Object.rpc [as updateValue] (/home/ganesh/Documents/Blockchain/solana/myproject/node_modules/@project-serum/anchor/dist/cjs/program/namespace/rpc.js:9:24)
at TestFunc (/home/ganesh/Documents/Blockchain/solana/myproject/tests/myproject.js:28:31)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
This problem can be solved by converting the number to the bignumber.
the solution is provided as below :
const anchor = require('@project-serum/anchor')
/*
--------------
-----------
code body
-------------
------------------
*/
const value = new anchor.BN(40);
let tx2 = await program.rpc.updateValue(value, {
accounts: {
storageAccount: account.publicKey,
},
// signers: [account],
})
console.log('Your transaction signature', tx2)
where the updateValue accpets the context and integer in the solana anchor program as given below :
pub fn update_value(ctx: Context<UpdateValue>, value : u64) -> Result<()> {
let storage_account = &mut ctx.accounts.storage_account;
storage_account.value = value;
Ok(())
}