Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nearprotocol 找不到合同方法_Nearprotocol - Fatal编程技术网

Nearprotocol 找不到合同方法

Nearprotocol 找不到合同方法,nearprotocol,Nearprotocol,因此,我在index.ts中工作,我的合同代码在那里,我在utils.js中添加了我的方法,并在控制台中测试了我的功能,但收到了上述响应 index.ts import { Context, logging, storage, PersistentMap } from 'near-sdk-as' import { string } from 'prop-types'; // Key value pair // Value = array ; Key = voter ID let votersR

因此,我在
index.ts
中工作,我的合同代码在那里,我在
utils.js
中添加了我的方法,并在控制台中测试了我的功能,但收到了上述响应

index.ts

import { Context, logging, storage, PersistentMap } from 'near-sdk-as'
import { string } from 'prop-types';

// Key value pair
// Value = array ; Key = voter ID
let votersReg= new PersistentMap<string, bool>("Voters Registration");
let candidateReg= new PersistentMap<string, i32>("Candidate Registration");

// Context.sender == 'usernmae.testnet'

export function addVote(candidate:string):i32{
    if(!votersReg.contains(Context.sender)){
        votersReg.set(Context.sender, true)
        if(!candidateReg.contains(candidate)){
            candidateReg.set(candidate, 1)
        }
        else{
            let currentCount=candidateReg.getSome(candidate);
            currentCount += 1;
            candidateReg.set(candidate, currentCount);
        }  
    }
    else{
        logging.log("You have already voted!")
    }
    return candidateReg.getSome(candidate)
}

export function getVotes(candidate:string):i32{
    if(candidateReg.contains(candidate)){
        return candidateReg.getSome(candidate)
    }
    else {return 0}
}
使用
wait window.contract.addVote({candidate:“dummy”})测试
addVote()
,返回

Failure [dev-1605381216128-9269896]: Error: Contract method is not found
printLogsAndFailures @ account.js:62
signAndSendTransaction @ account.js:132
async function (async)
signAndSendTransaction @ account.js:77
signAndSendTransaction @ wallet-account.js:159
async function (async)
signAndSendTransaction @ wallet-account.js:151
functionCall @ account.js:223
(anonymous) @ contract.js:47
addVote @ contract.js:14
(anonymous) @ VM77:1
errors.js:19 Uncaught Error: Contract method is not found
    at Object.parseRpcError (rpc_errors.js:38)
    at ConnectedWalletAccount.signAndSendTransaction (account.js:139)
    at async ConnectedWalletAccount.signAndSendTransaction (wallet-account.js:159)
    at :1234/async http:/localhost:1234/src.e31bb0bc.js:48839
    at :1234/async <anonymous>:1
json-rpc-provider.js:69 Uncaught Error: Querying call/dev-1605381216128-9269896/getVotes failed: wasm execution failed with error: FunctionCallError(MethodResolveError(MethodNotFound)).
{
  "error": "wasm execution failed with error: FunctionCallError(MethodResolveError(MethodNotFound))",
  "logs": [],
  "block_height": 24423413,
  "block_hash": "96FXs7Y2a53uvfpuJhm9eU8asjNicf87SbqwFGvmBn6K"
}
    at JsonRpcProvider.query (json-rpc-provider.js:68)
    at async ConnectedWalletAccount.viewFunction (account.js:276)
    at :1234/async <anonymous>:1

我不太清楚这里发生了什么。我的印象是,我不需要在测试之前部署我的合同,也许这就是把事情搞砸的原因,但我认为部署合同是最后一步。提前感谢您的帮助

您确实需要部署合同来测试它们。您必须对添加的每个函数执行此操作,才能使其在前端可用。

在README.md下的“创建近距离应用程序->读取”“NEAR中的每个智能合约都有自己的关联帐户。当您运行npm-run-dev时,您的智能合约将使用一次性帐户部署到liveneartestnet。当您准备将其永久化时,下面是如何实现的。“这不意味着我可以简单地使用npm run dev测试方法吗?或者我必须完成步骤1、2和3并运行
npm run deploy
?thaks
json-rpc-provider.js:69 Uncaught Error: Querying call/dev-1605381216128-9269896/getVotes failed: wasm execution failed with error: FunctionCallError(MethodResolveError(MethodNotFound)).
{
  "error": "wasm execution failed with error: FunctionCallError(MethodResolveError(MethodNotFound))",
  "logs": [],
  "block_height": 24423413,
  "block_hash": "96FXs7Y2a53uvfpuJhm9eU8asjNicf87SbqwFGvmBn6K"
}
    at JsonRpcProvider.query (json-rpc-provider.js:68)
    at async ConnectedWalletAccount.viewFunction (account.js:276)
    at :1234/async <anonymous>:1