Threads
January 5th, 2022
We have currently 10 threads for the above date.
🛠 │ dev-support
status - Resolved
sinnrrr --> how can I dev-deploy
to a new dev account, instead those, defined in ~/.near-credentials
?
Benji | NEAR --> use the -f
flag so near dev-deploy --wasmFile PATH_TO_WASM -f
sinnrrr --> thanks!
🛠 │ dev-support
status - Resolved
sinnrrr --> I have this method on contract
pub fn get_advertised_token(&mut self) -> TokenId {
self.advertised_token_id.clone().unwrap()
}
when I call it with near view $NFT_ID get_advertised_token
($NFT_ID is defined with account ID), it throws following error:
commercial/nfthell [feat/market●] » near view $NFT_ID get_advertised_token
View call: dev-1641392269422-38144516701962.get_advertised_token()
An error occured
Error: Querying [object Object] failed: wasm execution failed with error: FunctionCallError(MethodResolveError(MethodNotFound)).
{
"error": "wasm execution failed with error: FunctionCallError(MethodResolveError(MethodNotFound))",
"logs": [],
"block_height": 77768008,
"block_hash": "Cq4nCkoUwhzYobVy3YWarWqD2HsJ5iZsiYYNQoZLSrx"
}
at JsonRpcProvider.query (/Users/dmytro/.config/yarn/global/node_modules/near-api-js/lib/providers/json-rpc-provider.js:123:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Account.viewFunction (/Users/dmytro/.config/yarn/global/node_modules/near-api-js/lib/account.js:366:24)
at async exports.callViewFunction (/Users/dmytro/.config/yarn/global/node_modules/near-cli/index.js:94:48)
at async Object.handler (/Users/dmytro/.config/yarn/global/node_modules/near-cli/utils/exit-on-error.js:52:9)
Benji | NEAR --> are you sure you’re calling the correct contract?
sinnrrr --> yes, seems like this methods aren’t defined
sinnrrr --> I looked at available methods, and the contract doesn’t have that
sinnrrr --> here is how I create those methods
use crate::*;
#[near_bindgen]
impl Contract {
#[private]
pub fn select_advertised_token(&mut self, token_id: TokenId) {
self.advertised_token_id = Option::from(token_id)
}
pub fn get_advertised_token(&mut self) -> JsonToken {
self.nft_token(self.advertised_token_id
.clone()
.expect("No advertise token selected")
).unwrap()
}
}
sinnrrr --> but they don’t appear in list of methods on smart contract
Benji | NEAR --> is your code open sourced
sinnrrr --> yes, https://github.com/sinnrrr/nfthell/tree/feat/market
/contracts/nft/advertised_token.rs
Benji | NEAR --> that directory isn’t in main. Is it in a diff branch?>
sinnrrr --> yes, feat/market
sinnrrr --> I’ve forgotten
Benji | NEAR --> it’s still not there
Benji | NEAR -->
sinnrrr --> one second, I’ll commit
sinnrrr --> done
Benji | NEAR --> Everything works fine on my end. The only thing is that you have the function taking in &mut self
which makes it a non viewable function. Removing the &mut
and making it &self
worked for me.
sinnrrr --> correct, I guess I had issues with wrong account IDs, thanks for sparing time for this, really appreciate such a GREAT help! go team!
Benji | NEAR --> Go Team 🙂
🛠 │ dev-support
status - Unresolved
confusion summary: Seeking documentation for RPC rate limits on testnet and mainnet
ashutosha --> Hi! I am looking for documentation regarding rate limits on rpc.testnet.near.org and rpc.near.org. I couldn’t find it on docs.near.org. Can someone point me to it?
🛠 │ dev-support
status - Resolved
Monkeyboi --> Hello guys I’m trying to send batch transaction using the near-api-js library. But when i send argument which is serialized using “Buffer.from(JSON.stringify(args))”, the smart contract panicked. Anybody can help me?
Monkeyboi -->
Benji | NEAR --> You’re not passing in the correct arguments. I would need to see your code to help debug
Monkeyboi --> sir it just got normal, happened to be a mismatch of types from previous argument. Ty
🛠 │ dev-support
status - Resolved
Yaroslav Khodakovskij --> Hi everyone, I’ve encountered a problem. I’m using nearprotocol/nearup:1.2.1 container with nearprotocol/nearcore:1.22.0 to run localnet node for local development. The problem is that sometimes all transactions like deploy contract or create account stop working with the error “The node does not track the shard ID 0”. The problem is a floating one and happens once in 1-4 days. The problem is in a blockchain state - if the data by the /root/.near path is dropped, the problem disappears. At first, I thought that the problem is related to querying historical data(https://github.com/near/nearcore/issues/4340), but sometimes it happens before 2 days have passed after a container launch.
Also, I’ve looked into node logs after a problem occurred and it looks like blocks are rejected due to “already known in blocks with missing chunks” and “already known in orphans”. But I don’t know if it’s related.
Is this a known issue? Is there a way to solve it and avoid dropping blockchain state periodically?
Benji | NEAR --> I would ask in the indexer support TG chat. I’m honestly not sure cc <@!khorolets>
khorolets --> On localnet epochs are shorter, so it’s not about a couple of days. I’d suggest you to change archival param in config.json to true. It more convenient way to develop on localnet
Yaroslav Khodakovskij --> I’ll try it, thanks for a suggestion!
Mouradif --> Hi <@!Yaroslav Khodakovskij> did you manage to fix your problem ?
🛠 │ dev-support
status - Resolved
silencebringer69 --> I am not being able to set the state of contract.
https://explorer.testnet.near.org/transactions/4irZDmbq5L9UprgREu6nh5hAk8QpanVemN2ANcxEBUvx
export const deployContract = async(subAccount,gameName) => {
//water fighter
const response = await subAccount.deployContract(nearCredintials.ftWasm);
console.log(‘response: ‘, response)
console.log(gameName.split(' ').join('').toLowerCase(),
, gameName.split(’ ‘).join(’’).toLowerCase(),)
var gamename = gameName.split(’ ‘).join(’’).toLowerCase();
var metadata = {
spec: “ft-1.0.0”,
name:gamename,
symbol: “HF”,
decimals: 10
}
console.log(metaData
, metadata);
let contractId = subAccount.accountId;
console.log(contractId
, contractId)
const subContract = new Contract(
subAccount, // the account object that is connecting
contractId,
{
// name of contract you’re connecting to
viewMethods: [“getMessages”], // view methods do not change state but usually return a value
changeMethods: [“ft_transfer”,“new”], // change methods modify state
sender: subAccount, // account object to initialize and sign transactions.
}
);
console.log(subContract
, subContract)
const rateInYocto = utils.format.parseNearAmount(“2.5”);
const ress = await subContract.new(
{
owner_id: subAccount.accountId,// argument name and value - pass empty object if no args required
total_supply:JSON.stringify(1000000000000000),
metadata:metadata,
rate:rateInYocto
}, 300000000000000
// attached GAS (optional)
);
console.log(ress here
, ress)
}
Benji | NEAR --> Did you deploy the correct wasm file?
silencebringer69 --> Yeah I believe I did. I was able to call the new function through CLI
https://explorer.testnet.near.org/transactions/HNdr171Aipp9Z98cwMDDYqS5bnKyPM49aGyGwr9iZBWa
Benji | NEAR --> Thé code you linked above is for a different account ID. It’s for hameedfighter.metamon3.testnet not fungible.fungibletest.testnet
silencebringer69 --> Yeah but I used the same wasm file.
Benji | NEAR --> Can you send me the wasm file and I’ll try on my end
silencebringer69 --> I was thinking about it. Give it a try
Benji | NEAR --> I’m getting the same error… this is so strange 0.o perhaps there’s something going on with javascript and not being able to properly deploy the same wasm the same was the cli does it…
Benji | NEAR --> https://explorer.testnet.near.org/transactions/39mfG76BZmpW3HXboNAKGpUcQQeDueuzVXqJNXHvdagj
Benji | NEAR --> https://explorer.testnet.near.org/transactions/G3LGrw7iAnNnYDZcCkEz6k6ZkQgyAZd3MBQKmdSbf9xn
Benji | NEAR --> two transactions, one successful one not both with the same wasm file. One was with CLI and one was through javascript
Benji | NEAR --> cc <@!Josh | NEAR> do you have any ideas? I’m honestly not sure
Benji | NEAR -->
Benji | NEAR --> using a wasm bot to get me the methods of both accounts, it can’t properly return the methods for the contract deployed using NAJ
Benji | NEAR --> the one from CLI works fine
silencebringer69 --> Thanks for looking into it. I hope Josh can help us out.
Josh | NEAR --> Here is how you deploy a contract using NAJ (near-api-js
)
https://docs.near.org/docs/api/naj-cookbook#deploy-contract
Josh | NEAR --> cc <@!silencebringer69>
silencebringer69 --> The contract was deployed successfully, but we are not being able to call any method. What are we doing wrong?
https://explorer.testnet.near.org/transactions/CZMLhrrYYbhRK6KYjaErHQcD3HVu2edTCKoRCCwURPxT#HBxjx4kje7qYSxav2bforcRgUL3YisL6sRaHWq2Hyc8F
https://explorer.testnet.near.org/transactions/ANwKDetyPpstKH7Yq7oq3w5UfXiZbSDzWSZPSfDw7U7B#GEwzty38jbTszn1GETkuGjUGcLVqnWi2kz5jZwMFSAUr
cc: <@!Benji | NEAR>
Benji | NEAR --> Honestly not sure <@!Serhii> do you have any ideas? Same wasm being deployed using CLI and JS but the CLI method works and the JS method leads to the EVMs not being able to read the wasm properly and you get a deserialization error
Serhii --> It’s hard to say. <@!silencebringer69> can you please provide the CLI command and JS code snippet (in text) so we can try it ourselves?
Is there two accs? Can you provide acc Ids? Have you compared contract hashes?
Benji | NEAR --> Cc <@!Serhii> hère is more info
Benji | NEAR --> Here is code snippet:
Benji | NEAR --> ```javascript
const keyStore = new keyStores.InMemoryKeyStore();
const ACCOUNT_ID = “benjiman.testnet”; // NEAR account tied to the keyPair
const NETWORK_ID = “testnet”;
keyStore.setKey(NETWORK_ID, ACCOUNT_ID, KeyPair.fromString(""));
const config = {
networkId: "testnet",
keyStore, // optional if not signing transactions
nodeUrl: "https://rpc.testnet.near.org",
walletUrl: "https://wallet.testnet.near.org",
helperUrl: "https://helper.testnet.near.org",
explorerUrl: "https://explorer.testnet.near.org",
};
const near = await connect(config);
let keyPair = await KeyPair.fromRandom('ed25519');
let pubKey = keyPair.getPublicKey();
const subAccountId = "silencebringer-contract-test3.benjiman.testnet";
const account = await near.account("benjiman.testnet");
await account.createAccount(
subAccountId, // new account name
pubKey, // public key for new account
parseNearAmount("1") // initial balance for new account in yoctoNEAR
);
keyStore.setKey(NETWORK_ID, subAccountId, keyPair);
console.log('keyStore: ', keyStore)
const subAccount = await near.account(subAccountId);
const response = await subAccount.deployContract("../game_token.wasm");
console.log('response: ', response)
var metadata = {
spec: "ft-1.0.0",
name:"foo",
symbol: "HF",
decimals: 10
}
const res = await subAccount.functionCall(
subAccountId, 'new', {
owner_id: subAccountId,// argument name and value - pass empty object if no args required
total_supply:JSON.stringify(1000000000000000),
metadata:metadata,
rate:parseNearAmount("2.5"),
}, GAS
);
console.log('res: ', res)
Benji | NEAR --> I can’t JS format it cuz I’m on phone
silencebringer69 --> Hi <@!Serhii> ! We are creating sub-account and are deploying our contract on sub-account(which we are able to do successfully). Once the contract is deployed we are trying to set its state by calling the **"new_ft"** function. Once we call that function from frontend we get the error "Error happened while deserializing the module".
**The parameters we are passing through CLI are:**
{\"owner_id\": \"fungible2.fungibletest.testnet\", \"total_supply\": \"1000000000000000\", \"metadata\": { \"spec\": \"ft-1.0.0\", \"name\": \"Example Token Name\", \"symbol\": \"EXLT\", \"decimals\": 8 },\"rate\" : \"2500000000000000000000000\"}
**The command:**
near call game-token.ahsans.testnet new_ft '{\"owner_id\": \"fungible2.fungibletest.testnet\", \"total_supply\": \"1000000000000000\", \"metadata\": { \"spec\": \"ft-1.0.0\", \"name\": \"Example Token Name\", \"symbol\": \"EXLT\", \"decimals\": 8 },\"rate\" : \"2500000000000000000000000\"}' --accountId game-token.ahsans.testnet
The code can be found as an attachment to this message(shared by <@!Benji | NEAR> already. Thanks to him).
silencebringer69 -->
Serhii --> <@!silencebringer69> it's not the best way to deploy and init your ft contract. I would recommend you to use batch actions.
https://github.com/near/near-api-js/blob/master/examples/cookbook/transactions/batch-transactions.js
Serhii --> Here is a good example to experiment with.
Benji | NEAR --> Why not out of curiosity?
Serhii --> There is no point to deploy contract without initializing it right after that. In the end you want to have initialized FT contract or nothing, so it's better to batch this actions. Also, somebody else can initialize it if you will not be fast enough 🙂 with batch actions it's imposiible.
Benji | NEAR --> but that doesn't explain the deserialization error though right?
Serhii --> Sorry for the confusion. No, it does not explain the error. But example code is short and clear. It will be easier to debug and find the reason of our problem if we will have one after this small refactoring.
Benji | NEAR --> Ill mess around and ping if im still having problems thanks!
silencebringer69 --> Thanks <@!Serhii> ! I will give it a try and ping in case of any issue. 🙂
silencebringer69 --> Hi! We are receiving the same error. <@!Benji | NEAR> did you get to give it a try?
Serhii --> What is your contract file? Is it a standard FT contract, or you have modified it?
Can you deploy the same contract with NEAR CLI and then call `new` function?
silencebringer69 --> Hi <@!Serhii>
It's a .wasm file. I hav slightly modified the struct of Contract (add an attribute named as rate). I am able to deploy the same contract from NEAR-CLI. I am sharing the WASM file and JS script just in case.
Please unzip the file and run the following (make sure you are in the directory)
> node nearSubAccountFunction.js scream
The name of the function is "new_ft"
https://explorer.testnet.near.org/transactions/HNdr171Aipp9Z98cwMDDYqS5bnKyPM49aGyGwr9iZBWa (succeeded using near cli)
https://explorer.testnet.near.org/transactions/9RBThPHWTDoxYiAUzAxmTG4HfLhL8ehFNPrXtS6LSfCU (failed using near-js-api)
silencebringer69 --> <@!Serhii> The issue has been resolved. The path to wasm file was incorrect secondly, the balance transferred to the subaccount should be at least 20N in order to call the 'new' function.
cc: <@!Benji | NEAR>
Thank you <@!Serhii> <@!Benji | NEAR> for your support 🙂
Josh | NEAR --> I've never seen this before and not sure who created it. Checkout our docs on `near-api-js` for a guide on wiring up your front-end
https://docs.near.org/docs/api/naj-quick-reference
Benji | NEAR --> I've not tried anything yet - been swamped with other stuff
🛠 │ dev-support
status - Resolved
confusion summary: Library that handles floating numbers in Near
resolution summary: One could use f64, but it's discouraged because it easily loses precision.
illus --> Is there any library which handles floating numbers in Near? I couldn’t use decimal crate because it doesn’t implement BorshSerialize trait. I searched a lot, but i could only find this related one.
https://stackoverflow.com/questions/65770753/can-i-use-floating-points-in-near-protocol
Can I just use f64 type in Near?
Dorian | NEAR --> let me ping someone for you
austinabell --> yes, you can absolutely use f64
inside a contract, but it is generally discouraged because it is easy to lose precision and cause a logical bug in the functionality of the contract. A common pattern that contracts will do is use integers internally and just do some division based on what precision you want for the view methods or externally 🙂
🛠 │ dev-support
status - Unresolved
psalomo --> <@!chefsale> would it be possible to deploy the latest NEAR fastrpc? I need this fix here: https://github.com/vgrichina/fast-near/commit/004061ba86d528e11c0573c08b1d8a059af8a948 to be able to show NFT images in the wallet for my contract.
🛠 │ dev-support
status - Unresolved
Vlodkow --> Hello team, is there any additional information about web4? I already checked https://web4.near.page/ but it is just for Assembly Script? I using Rust, can I have web4 functionality for my frontend?