Can not call the function Aggregate - Multicall2.sol on BSC testnet - solidity

I already deployed the multicall2.sol smart contract on BSC Testnet
https://testnet.bscscan.com/address/0x8F3273Fb89B075b1645095ABaC6ed17B2d4Bc576#code
then call the contract by using the following typescript code:
try {
const multi = getMulticallContract(options.web3 || web3NoAccount)
const itf = new Interface(abi)
const calldata = calls.map((call) => [call.address.toLowerCase(), itf.encodeFunctionData(call.name, call.params)])
const { returnData } = await multi.methods.aggregate(calldata).call(undefined, options.blockNumber)
const res = returnData.map((call, i) => itf.decodeFunctionResult(calls[i].name, call))
return res
} catch (error) {
throw new Error(error)
}
}
I got the error
Uncaught (in promise) Error: Error: Returned error: execution reverted: Multicall aggregate: call failed
It's weird. Because the function works properly on Mainnet. Can anyone help me?

The author found his solution but just to complete the troubleshooting I suggest making sure you have:
Have the contract deployed on testnet
Switch your RPC Node Url to the correct network. For example: BSC testnet's is https://data-seed-prebsc-1-s2.binance.org:8545

in my case, i resolved the issue by simply switching the rpc from https://data-seed-prebsc-1-s3.binance.org:8545/ to https://data-seed-prebsc-1-s2.binance.org:8545/
looks like they have some substantial inconsistency between nodes

Related

Invalid character when try to deploy or use a function from my contract using Web3Js

I keep trying to deploy to a contract or use a contract, but every time I deploy or use a function, I only get this error
error Error: Magic RPC Error: [-32603] Internal error: Invalid character
at sdk:11:8488
My contract is correct, I also deployed using a hardhat tool and everything was ok, but if I give them via web3.js I only have problems
const fromAddress = (await web3.eth.getAccounts())[0];
console.log(fromAddress);
console.log(contractAbi);
const contract = new web3.eth.Contract(JSON.parse(contractAbi));
console.log(contract);
// Deploy contract with "Hello World!" in the constructor and wait to finish
const contractInstance = await contract
.deploy({
data: contractByteCode
})
.send({
from: fromAddress,
gas: 200000
})
.on('error', (error) => {
console.log("error", error);
});
console.log(contractInstance);
The Abi and the byte code have no problems.. what could it be?
let contractAbi = '[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"string","name":"_promocode","type":"string"},{"internalType":"uint256","name":"_expirationDatetime","type":"uint256"}],"name":"addPromocode","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_identifier","type":"string"}],"name":"addWallet","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"string","name":"_identifier","type":"string"}],"name":"addWalletOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"checkWallet","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"string","name":"_promocode","type":"string"}],"name":"getPromocode","outputs":[{"components":[{"internalType":"string","name":"promocode","type":"string"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"generationDatetime","type":"uint256"},{"internalType":"uint256","name":"expirationDatetime","type":"uint256"},{"internalType":"bool","name":"status","type":"bool"}],"internalType":"structEWalletContract.Promocode","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"}],"name":"getUserBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"getUserPromocodes","outputs":[{"components":[{"internalType":"string","name":"promocode","type":"string"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"generationDatetime","type":"uint256"},{"internalType":"uint256","name":"expirationDatetime","type":"uint256"},{"internalType":"bool","name":"status","type":"bool"}],"internalType":"structEWalletContract.Promocode[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"string","name":"_promocode","type":"string"}],"name":"sendPromocode","outputs":[{"components":[{"internalType":"string","name":"promocode","type":"string"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"generationDatetime","type":"uint256"},{"internalType":"uint256","name":"expirationDatetime","type":"uint256"},{"internalType":"bool","name":"status","type":"bool"}],"internalType":"structEWalletContract.Promocode","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testContract","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"transaction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_promocode","type":"string"}],"name":"usePromocode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"userTransactions","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"}],"internalType":"structEWalletContract.Transaction[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"usersCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]';

Provider Error : Provider : Transaction Reverted without Reason String

We have been working on Document Signing App which sends an email when a user uploads a document and sends it to sign to another 3-4 users.
The user gets the email and tries to sign the document which does a blockchain transaction whose status is always failed.
We have been trying to debug this but unfortunately we haven’t any details lately, We have tried various codes but no changes have changed the status of transaction.
Our System Details :
Provider : Alchemy
Network : Goerli / Localhost ( Hardhat node )
Local Dev : Hardhat
We also tried to use hardhat console.sol but we could not get any logs in the contract when using Hardhat node, No logs were printed using npx hardhat test.
We have been facing this problem since almost a week now and the transaction is stil failing.
Snapshot of Local Error :
ProviderError: Error: Transaction reverted without a reason string
at HttpProvider.request (node_modules/hardhat/src/internal/core/providers/http.ts:78:19)
at GanacheGasMultiplierProvider.request (node_modules/hardhat/src/internal/core/providers/gas-providers.ts:312:34)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Smart Contract that is failing in actual transaction :
function sign(bytes32 hash, bytes32 signatureHash, address signer) public {
console.log("Entered Sign Function");
require(checkDoc(hash),"check doc failed");
require(documents[hash].signers[signer] == 1, "signer failed");
documents[hash].remainingSignatures--;
documents[hash].signers[signer] = block.timestamp;
emit Signature(hash, signatureHash, signer, 'Signature');
if (documents[hash].remainingSignatures == 0){
documents[hash].status = currentState.signed;
emit Signed(hash, 'Signed');
}
Require is not the issue because when we comment out require statements the transaction is still failing.
Code for Test case that is failing :
it("Signing contract", async function () {
const DocumentSigning = await ethers.getContractFactory("DocumentSigning");
const document_signing = await DocumentSigning.deploy();
const transactionOptions = {
gasLimit: 2500000
}
await document_signing.sign("0x46742b637a5c1d01460033c3bd178d1fafe78e0dffa5d2d1841dcccaf70d30a9", "0xef02795fa1b0c97abe843fb461b4625a6a24662bff227862d7d292c9fc69c1ab", "0x07906aae1204f6f3b81673562db7776af9acf83c", transactionOptions);
});
});
The values for test cases have been hardcoded for now to test the actual transaction flow.
Can some help on this as soon as possible?
Adding link to a sample transaction that failed :
https://goerli.etherscan.io/tx/0x4c1665f793541846457a27467236d5fccca63588be3064c78682f666393adc74

How to get web3 accounts in solc?

My blockchain project with solc version ^0.4.6 . Has been throwing errors when given the command of being web3.eth.accounts.
web3.eth.accounts
Uncaught Error: Invalid JSON RPC response: undefined
at Object.InvalidResponse (E:\techdot-master\node_modules\web3\lib\web3\errors.js:38:16)
at HttpProvider.send (E:\techdot-master\node_modules\web3\lib\web3\httpprovider.js:91:22)
at RequestManager.send (E:\techdot-master\node_modules\web3\lib\web3\requestmanager.js:58:32)
at Eth.get [as accounts] (E:\techdot-master\node_modules\web3\lib\web3\property.js:107:62).
I have tried reading the docs and tried other commands. Still unable to resolve the issue!
"Invalid JSON RPC response" means you are not connected to the node. In order to connect to a node, you need a provider. You can get an infura account and create a provider HdWalletProvider
const HDWalletProvider = require("#truffle/hdwallet-provider");
const provider = new HDWalletProvider({
mnemonic: {
phrase: metamask_mnemonic,
},
providerOrUrl: ropsten_network,//infura endpoint here
});
Or if you are using ganache-cli
const ganache = require('ganache-cli');
const provider = ganache.provider()
Then create web3
const web3 = new Web3(provider);
I think instead of accounts, should be getAccounts
const accounts = await web3.eth.getAccounts();
I recommend using ehtersjs, with it everything is a lot easier.

AWS Cognito JS SDK returning "AdminUpdateUserAttributes is not a function" error message

I'm trying to create a function which allows me to update a user's phone number in a Cognito User Pool. The code is in a NodeJS application, using the latest aws-sdk library.
I have this function callback structure working for a number of other actions against the user pool, e.g. creating and listing users, updating MFA, etc. So I am confident there's nothing structurally wrong with the way I have laid the code out.
But for this particular function, I am receiving an error that says AdminUpdateUserAttributes "is not a function".
I've tried changing different attributes in case it's a phone number thing, but I got the same result.
function cognitoUpdatePhone(username, phoneNumber, callback) {
var params = {
UserPoolId: '<my pool Id>',
Username: username,
UserAttributes: {
phone_number: phoneNumber
}
};
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
cognitoidentityserviceprovider.AdminUpdateUserAttributes(params, function (err, data) {
if (err) {
callback(err, false);
}
else {
callback(null, true);
}
});
}
I'm getting following response from the server. The stack trace indicates the source of the error is: aws-sdk/lib/state_machine.js
message: 'cognitoidentityserviceprovider.AdminUpdateUserAttributes is not a function',
code: 'TypeError',
Encountered the exact same problem. Solved it by changing the first letter of the function to lowercase: adminUpdateUserAttributes
Try using this:
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({apiVersion: '2016-04-18'});

Hello world contract method call returns Unhandled rejection Error

This is my package.json:
{
"dependencies": {
"solc": "^0.4.16",
"web3": "^1.0.0-beta.20"
}
}
This is my smart contract code:
contract HelloWorld {
function displayMessage() constant returns (string) {
return "Hello from a smart contract";
}
}
I've compiled this contract on the node repl with testprc running, and I'm trying to call the displayMessage method like so:
myContract.methods.displayMessage().call()
or
myContract.methods.displayMessage.call()
but I'm just getting this error:
> Unhandled rejection Error: ERROR: The returned value is not a convertible string:
at SolidityTypeString.formatOutputString [as _outputFormatter] (/Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-abi/src/formatters.js:245:15)
at /Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-abi/src/type.js:246:25
at SolidityTypeString.SolidityType.decode (/Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-abi/src/type.js:247:11)
at /Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-abi/src/index.js:327:49
at Array.forEach (<anonymous>)
at ABICoder.decodeParameters (/Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-abi/src/index.js:326:13)
at Contract._decodeMethodReturn (/Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-contract/src/index.js:490:22)
at Method._parent._ethereumCall.call.method.outputFormatter (/Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-contract/src/index.js:820:42)
at Method.formatOutput (/Users/alberthu/Documents/solidity-intro/node_modules/web3-core-method/src/index.js:179:54)
at sendTxCallback (/Users/alberthu/Documents/solidity-intro/node_modules/web3-core-method/src/index.js:446:33)
at /Users/alberthu/Documents/solidity-intro/node_modules/web3-core-requestmanager/src/index.js:144:9
at XMLHttpRequest.request.onreadystatechange (/Users/alberthu/Documents/solidity-intro/node_modules/web3-providers-http/src/index.js:64:13)
at XMLHttpRequestEventTarget.dispatchEvent (/Users/alberthu/Documents/solidity-intro/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/Users/alberthu/Documents/solidity-intro/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/Users/alberthu/Documents/solidity-intro/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.<anonymous> (/Users/alberthu/Documents/solidity-intro/node_modules/xhr2/lib/xhr2.js:469:24)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1059:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
I've tried reading through the web3 api docs but I'm new to this and haven't found anything useful. Anyone know how I can get "Hello from a smart contract" to show on the server?
Thanks!
I have the same problem. And insert correct contract address.
My contract (example from documentation web3js) I use web3.1.0.0-beta.23.
pragma solidity ^0.4.18;
contract MyContract {
function myFunction() returns(uint256 myNumber, string myString) {
return (23456, "Hello!%");
}
}
code
const contract = new web3.eth.Contract(abi, contractAddress);
contract.methods.myFunction().call()
.then(res => console.log(res))
.catch(e => console.log(e.message))
contract creating and send from test net good. But if I tried call methods - have the same error:
ERROR: The returned value is not a convertible string:
I am also learning how to code smart contracts and came across this error earlier today. I found what was causing it was that I had the wrong address tied to my smart contract.
Contract objects in web3 have an address property which represents the address used for that contract instance. In my case this address was incorrect and was causing me to have the same error. The contract address should have been returned to you after your deployment.
The correct contract address should have been returned to you in a callback function after you deployed it.
You can set and check your contract address as follows:
myContract.options.address // returns the current address you have set for this contract instance
myContract.options.address = "the correct contract address"
I would have left this as a comment but unfortunately I do not have enough reputation. Let me know if you need some more help or want to get together to learn.
Here is the web3js documentation on contract address property: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#options-address