In ethereum, we can sign a message and verify it onchain if the signer is correct. How can we do this in smart contract near_sdk_rs?
Use the environment function env::ecrecover(hash, signature, v, malleability_flag), to get the signer's public key from his signed message hash and signature.
https://docs.near.org/develop/contracts/environment/#environment-functions
Related
Suppose I have a solidity contract deployed at address X in Hedera testnet. I want to call a function from the contract deployed at contract X a get function that returns an array of structs...how do I decode that array of structs? (I am using ContractCallQuery function from the Hedera JS SDK library to call the get function) Ref: Link
As IVotes is a interface and cannot be deployed.
IVotes public immutable token;
constructor(IVotes tokenAddress) {
token = tokenAddress;
}
....
Error: *** Deployment Failed ***
"IVotes" is an abstract contract or an interface and cannot be deployed.
Import abstractions into the '.sol' file that uses them instead of deploying them separately.
Contracts that inherit an abstraction must implement all its method signatures exactly.
A contract that only implements part of an inherited abstraction is also considered abstract.
I want to use IVotes address passing in GovernorVotes constructor.
I tried bunch of methods but none works
The Solidity snippet, that you shared, expects a contract on the tokenAddress to implement the IVotes interface.
But it needs to be a "full" contract with all function bodies - not just the function declarations.
I'd like to create a function
(deposit-fungible-v2-burn (account:string amount:decimal token:module{fungible-v2}))
that burns amount tokens from the account.
Are there any functions in the fungible-v2 interface for minting/burning coins?
It is perhaps possible to use ROOT account from the token contract, but in that case ROOT would not be an eater account as this account can send(mint) tokens. It is also possible to use custom logic in the token contract itself, but in that case I would not be able to generalize the function for all fungible-v2 tokens.
No, though I believe the credit/debit functions provide similar functionality. To my knowledge, the burn function from ERC-20 is actually part of an extension to the ERC-20 standard and is not part of the standard itself (see https://docs.openzeppelin.com/contracts/3.x/api/token/erc20#ERC20Burnable ).
You could always try adding your own KIP here to add an extension interface: https://github.com/kadena-io/KIPs
I'm studying Uniswapv2 codes and I got stucked with ABI. https://github.com/Uniswap/v2-core/blob/master/contracts/UniswapV2Pair.sol
Why use ABI with call method, even if we can call transfer function from interface directly?
bytes4 private constant SELECTOR = bytes4(keccak256(bytes('transfer(address,uint256)')));
.
.
.
function _safeTransfer(address token, address to, uint value) private {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'UniswapV2: TRANSFER_FAILED');
}
I've read a lot about ABI, and I'm confused about some says that it is JSON format and some says it is byte form. What is right?
You can use short form, like your example, without full ABI.
ABI for web3js is JSON form. Its used for simply call all existed functions and parameters. If you use many function and parameters -- JSON ABI much better for use.
You used short hacked version with selector - this is not good readable style of code.
1-
I believe token.call(abi.encodeWithSelector(SELECTOR, to, value)); token is another contract instance and called inside a contract. call is used to execute code of another contract
2-
The ABI encodes information about smart contracts' functions and events.
It acts as an interface between EVM-level bytecode and high-level smart
contract program code. To interact with a smart contract deployed on the
Ethereum blockchain, external programs require an ABI and the address
of the smart contract. The ABI consists of the following:
• All function names
• Input and output types of functions
• All event names and their parameters
Contract has hex representation and binary representation:
Contract.abi : This contains the ABI of the smart contract in JSON format.
Contract.bin : This contains the hex representation of binary of the smart contract code.
I have contract in solidity MasterChef.sol which can be seen at the link below
https://github.com/pancakeswap/pancake-farm/tree/master/contracts
I want to deploy it using truffle on the Binance smart chain and the question is that the constructor of the MasterChef.sol takes in 5 args and two of them are contracts I want to know that how to pass the other two contracts i.e CakeToken.sol and SyrupBar.sol as the first two args in the deploy_contracts.js file.
You need deploy other contracts beforehand, write down their addresses and pass addresses when MasterChef is deployed.