I'm trying to get sender accountId in contract and getting error.
My contract:
#nearBindgen
export class Contract {
private message: string = 'Hello '
helloWorld(): string {
const predecessor = Context.predecessor
return this.message + predecessor
}
}
I'm trying to access contract from CLI with following command(with my account id):
near view $CONTRACT helloWorld --accountId <id>.testnet
Error:
Error: Querying [object Object] failed: wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView { method_name: "predecessor_account_id" })).
Oops. I should use
near call
instead of
near view
Related
I am just trying to follow the steps mentioned in the README.md file to send a simple call (link). I get the following error while trying to send the call using python substrate interface.
SubstrateRequestException: {'code': 1002, 'message': 'Verification Error: Runtime error: Execution failed: ApiError(FailedToConvertParameter { function: "validate_transaction", parameter: "tx", error: Error { cause: Some(Error { cause: Some(Error { cause: None, desc: "out of range decoding Compact<u32>" }), desc: "Could not decode `Call::call.2`" }), desc: "Could not decode `Call::EVM.0`" } })', 'data': 'RuntimeApi("Execution failed: ApiError(FailedToConvertParameter { function: \\"validate_transaction\\", parameter: \\"tx\\", error: Error { cause: Some(Error { cause: Some(Error { cause: None, desc: \\"out of range decoding Compact<u32>\\" }), desc: \\"Could not decode `Call::call.2`\\" }), desc: \\"Could not decode `Call::EVM.0`\\" } })")'}
Is it because I am missing some custom types when instantiating the substrate interface? If so what should I add to the custom types?
I already added the custom types mentioned at the top of the README.md.
I am trying to build a simple coin flip game in solana.
Full code here
I get this error:
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0
I followed some tutorials on how to use PDA's but couldn't find a report/workaround to an error as such.
Tests are running on localhost
I did some research and it might be that the account was already initialized ( maybe, no idea)
the part that is giving the error:
try {
await program.rpc.initialize(bump,
{
accounts: {
treasury: treasuryPda, // publickey for our new account
user: provider.wallet.publicKey,
systemProgram: SystemProgram.programId // just for Anchor reference
},
});
} catch (error) {
console.log("Transaction error: ", error);
console.log("blabla:", error.toString());
}
I'm new in blockchain, smart contract and near protocol. I'm trying to learn from https://near.academy/ . There's a sample contract on testnet : museum.testnet.
I'm using windows and i installed wsl2.
I can login with
near login command. But after that, when i called near view museum.testnet getmemecount command its giving me error below. Can anyone help me on this?
View call: museum.testnet.getmemecount()
An error occured
Error: Querying [object Object] failed: wasm execution failed with error: FunctionCallError(MethodResolveError(MethodNotFound)).
{
"block_hash": "SZv8UsCeNXLkhjPa9KeZY6xJXmKNb6MLyKXqHVddiT5",
"block_height": 65109663,
"error": "wasm execution failed with error: FunctionCallError(MethodResolveError(MethodNotFound))",
"logs": []
}
at JsonRpcProvider.query (/home/cinar/.nvm/versions/node/v14.18.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:116:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Account.viewFunction (/home/cinar/.nvm/versions/node/v14.18.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:351:24)
at async exports.callViewFunction (/home/cinar/.nvm/versions/node/v14.18.0/lib/node_modules/near-cli/index.js:75:48)
at async Object.handler (/home/cinar/.nvm/versions/node/v14.18.0/lib/node_modules/near-cli/utils/exit-on-error.js:52:9)
TypedError: Querying [object Object] failed: wasm execution failed with error: FunctionCallError(MethodResolveError(MethodNotFound)).
{
"block_hash": "SZv8UsCeNXLkhjPa9KeZY6xJXmKNb6MLyKXqHVddiT5",
"block_height": 65109663,
"error": "wasm execution failed with error: FunctionCallError(MethodResolveError(MethodNotFound))",
"logs": []
}
at JsonRpcProvider.query (/home/cinar/.nvm/versions/node/v14.18.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:116:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Account.viewFunction (/home/cinar/.nvm/versions/node/v14.18.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:351:24)
at async exports.callViewFunction (/home/cinar/.nvm/versions/node/v14.18.0/lib/node_modules/near-cli/index.js:75:48)
at async Object.handler (/home/cinar/.nvm/versions/node/v14.18.0/lib/node_modules/near-cli/utils/exit-on-error.js:52:9) {
type: 'UntypedError',
context: undefined
}
The method name is get_meme_count, not getmemecount. See the source code of the museum here.
$ near view museum.testnet get_meme_count
View call: museum.testnet.get_meme_count()
67
Does some part of near academy mention it as getmemecount?
If I have the following method to test predecessor_account_id behaviour
pub fn get_pred_acc(&self) -> (String {
let prev_acc = env::predecessor_account_id().to_string();
return prev_acc;
}
And try to call this from frontend
const contract = await this.near.loadContract(window.nearConfig.contractName, {
viewMethods: ["get_pred_acc", ],
changeMethods: [],
sender: this.accountId,
});
const acc = await contract.get_pred_acc();
I get the following error:
Uncaught (in promise) Error: Querying call/flux-protocol/get_account_id failed: wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView("predecessor_account_id"))).
{ "error": "wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView(\"predecessor_account_id\")))",
"logs": []
}
That's expected behavior for the view calls.
The view calls don't have certain context information such calls are not part of an actual transaction.
Currently, the best option to see which methods are prohibited in the view calls is to take a look at the test: https://github.com/nearprotocol/nearcore/blob/master/runtime/near-vm-logic/tests/test_view_method.rs#L19-L43
To summarize:
previous account information and keys (signer, predecessor and signer_public_key)
gas information
all promise methods, cause they involve other contracts
I have a code distributed in 2 Script files. One is the logic.js provided by Hyperledger Composer Playground. And another script file - optedServices.js in which I have a function getService() defined. I need to call this function getService() in the code of logic.js. Please let me know how to do this. Thanks in advance - Madhu
I tried 'Add a file' link in the bottom left corner. And drag and dropped the optedServices.js and pressed 'add' button. That included the file in UI of playground.
The file logic.js contains:
function numToString(optedService) {
if (optedService == "") {
return ""
}
var optedService2 = require('./optedService');
optedServices = optedService2.getService('2' + optedService);
.......
return optedServices;
}
The file optedService.js contains:
function getService (number)
{
.
.
.
return 'Sting1 & String2';
}
module.exports = {
getService:getService
}
Expected result: 'Sting1 & String2'
Actual Result:
Error: Error trying invoke business network with transaction id 22b513d8dbbf765bd23e3f448c45d2464e19b6c35628e23989c0a25f6a018b49. Error: No valid responses from any peers. Response from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: ReferenceError: module is not defined