'Multiple Contracts: why is this compiling and deploying, but throwing an error on call?
So I have three contracts oganised into a folder as followed:
contract
|-src
||-file1.rs
||-file2.rs
||-lib.rs
|-Cargo.toml
The goal is to compile them into a single binary wasm file, and deploy as one contract to testnet. However, I am new to both near and rust; so am coming up against errors which are probably trivial to most people ... anyway:
Here, file1.rs holds the following:
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::{near_bindgen};
#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
pub struct Contract1 {
item : i8
}
#[near_bindgen]
impl Contract1 {
pub fn get(&mut self) -> i8 {
return self.item ;
}
}
And then there is file2.rs, who holds:
use near_sdk::borsh::{ self, BorshDeserialize, BorshSerialize};
use near_sdk::{ log, near_bindgen };
#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
pub struct Contrac2 {
test : u128
}
#[near_bindgen]
impl Contrac2 {
pub fn test(&mut self) {
log!("test");
}
}
And lib.rs, who holds:
pub mod bridge;
pub mod ft;
pub use bridge::*;
pub use ft::*;
The Cargo.toml file holds the following config:
[package]
name = "multi-deploy"
version = "0.1.0"
authors = [""]
edition = "2018"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
near-sdk = "4.0.0-pre.7"
When I compile the project, and deploy to testnet, it returns success, however, when calling any of the methods in any of the above contracts: test(), or get(), using:
require("dotenv").config();
const nearAPI = require("near-api-js");
const {parseSeedPhrase} = require("near-seed-phrase");
async function call() {
const mneumonic = process.env.nearmneumonic0?.trim() || "";
const ACCOUNT_ID = process.env.nearacct0?.trim() || "";
const ENDPOINT_API = process.env.nearAPI?.trim() || "";
const keyStores = nearAPI.keyStores;
const keyPair = nearAPI.KeyPair;
const connect_ = nearAPI.connect;
const keyStore = new keyStores.InMemoryKeyStore();
const PRIVATE_KEY = parseSeedPhrase(mneumonic);
const keyPair_ = keyPair.fromString(PRIVATE_KEY.secretKey);
await keyStore.setKey("testnet", ACCOUNT_ID, keyPair_);
const config = {
networkId: "testnet",
keyStore: keyStore,
nodeUrl: ENDPOINT_API,
};
const near = await connect_(config);
const account = await near.account(ACCOUNT_ID);
const contract = new nearAPI.Contract(
account,
ACCOUNT_ID,
{
viewMethods: ["get", "test"],
sender: account,
}
);
let response = await contract.test(
{
args: {},
gas: 300000000000000
}
);
console.log(response);
}
call();
The following error is returned:
TypedError: Querying [object Object] failed: wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView { method_name: "attached_deposit" })).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
