nearprotocol

How to send near tokens to payable function in near api js and near cli?

纵饮孤独 提交于 2021-01-28 11:45:04
问题 I have a following function in the contract: #[payable] pub fn buy_tokens(&mut self) { let amount = env::attached_deposit() } But how to call the function in near-api-js and near cli with attached near tokens deposit? await nearvar.contract.buy_tokens() Edit: await nearvar.contract.buy_tokens({}, GAS_AMOUNT, ATTACHED_DEPOSIT); Gives error {InvalidTxError: {InvalidAccessKeyError: "DepositWithFunctionCall"} The error seems because of function call action is not allowed with a function call

NEAR and safe math on unsigned integers

Deadly 提交于 2021-01-28 08:49:52
问题 On Ethereum Solidity, a special library called SafeMath needs to be used when dealing with unsigned integer balance number. This is because of the integer overflow exploits. Does NEAR smart contracts written in Rust need similar mitigations? Or does Rust trap the oveflow automatically and panic? 回答1: By default, Rust has overflow checks enabled for debug builds, but disabled in optimized release builds. You can easily tweak it in Cargo.toml by setting overflow-checks in profile.release

Why can't I read this HashMap in a NEAR contract?

∥☆過路亽.° 提交于 2021-01-28 07:50:34
问题 I have a NEAR smart contract that keeps a HashMap of Veggie records. My most basic accessor method get_veggie(vid), which looks up and returns one Veggie record, passes unit tests but fails in the deployed contract. It panics with 'veggie does not exist' when I send one of the keys returned by another accessor method, get_veggie_keys(). // this method returns an array of u64 keys: pub fn get_veggie_keys(&self) -> Vec<TokenId> { self.veggies.keys().cloned().collect() } // but this method

What is the proper length and format for public keys on NEAR

﹥>﹥吖頭↗ 提交于 2021-01-27 11:47:00
问题 Some public keys that are generated from storage devices are 44 characters after the ed25519: prefix (52 total) and some are 43 characters (51 total). Is this permissable? Is the ed25519: prefix necessary to include whenever using a public key? 回答1: ed25519: prefix is usually optional and is applied by default. It is ok for keys to have different length. A key is basically a large binary number encoded using base58 with leading zeros being dropped. Basically the same thing happening as if we

What is the proper length and format for public keys on NEAR

不羁的心 提交于 2021-01-27 11:45:08
问题 Some public keys that are generated from storage devices are 44 characters after the ed25519: prefix (52 total) and some are 43 characters (51 total). Is this permissable? Is the ed25519: prefix necessary to include whenever using a public key? 回答1: ed25519: prefix is usually optional and is applied by default. It is ok for keys to have different length. A key is basically a large binary number encoded using base58 with leading zeros being dropped. Basically the same thing happening as if we

How to attach value (deposit) to transaction with Nearlib?

荒凉一梦 提交于 2021-01-27 06:52:10
问题 Let's say I have a contract function that expects a certain amount of near to be send with a certain transaction, the function is called create_order , create_order takes a couple arguments. I have my contract setup in the frontend under the name myContract . I want to call myContract.create_order({...}) but the transaction fails because this method call doesn't have the right amount of NEAR tokens attached. How do I assign a certain value of deposit to a transaction? 回答1: Nearlib supports it

Contract method is not found

痴心易碎 提交于 2020-12-13 04:45:05
问题 So I'm working out of index.ts where my contract code is and utils.js where I added my methods and I'm testing my functions in the console but receive the above response. 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

What is the condition to be banned by the network in NEAR?

随声附和 提交于 2020-07-09 12:45:28
问题 It seems that there is a threshold to be kicked out from the validators on the epoch after the next, but it seems that you can get banned at the current epoch for not producing enough blocks. Is this the case? 回答1: Yes. There are multiple ways to get banned. For example, if you produced a block with invalid signature, your node will get banned. Alternatively, your node can get banned if you signal a peer that you have headers for them to sync from but do not actually give them headers at a

Sign and verify using ed25519 in near protocol

一笑奈何 提交于 2020-06-27 18:37:37
问题 I am trying to sign the message in javascript using signMessage and verify it with python for implementing jwt authentication. This is the code for signing message in javascript using near-api-js window.signer = await new nearlib.InMemorySigner(window.walletAccount._keyStore) const mysign = await window.signer.signMessage("Amiya", window.walletAccount._authData.accountId, window.walletAccount._networkId) let mypubdata = "" mysign.publicKey.data.forEach( function (item,index){ if(item < 16) {