I am trying to call a function from my contract using Netherums "SendTransactionAsync", however, it only works when the source is a public key rather than a private key.
I am using Ganache private network to test my contract.
Error: One or more errors occurred. (sender account not recognized: eth_sendTransaction)
This is my Code
HexBigInteger gas = new HexBigInteger(new BigInteger(400000));
HexBigInteger value = new HexBigInteger(new BigInteger(0));
myContract.GetFunction("giveFruit").SendTransactionAsync("b6558007a470f0593a35be45926342e92942fa3d7d00fc357c104fcc428f0cee", gas, value, "apple");
The first parameter of the function is the address that is supposed to call this function and the last parameter
is an item passed to the contracts function?
The contract is working fine however when the code above doesn't work if I use the private key as shown, on the other hand, if I replace the private key with a public key it works just fine.
This doesn't make any sense, as you shouldn't be allowed to send transactions using public keys.
Related
In BSC (Binance Smart Chain) contracts I often meet a signature parameter but I have no idea where to get it.
If you think that it is a signature message which you need to sign with Metamask - it's not. It's just a one of parameters of the function I need to run.
Example can be found there, just look at the purchase function and you'll see signature as a last parameter - https://bscscan.com/address/0xabc306ae80595f6c7748b81d6c2efc48b32a9e22#writeContract
Signature is a result of signing a message with a private key.
Example from the web3 docs page:
message Hello world
signed with the private key of address 0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe
results in signature 0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400
A contract can then verify if the signature and message (or hash of the message) can be recovered back to the signer address (cannot get the private key).
For example the OpenZeppelin ECDSA library is a developer-friendly wrapper for the low-level (EVM assembly) recovery method.
Unfortunately the contract linked in the question is passing the signature to another unspecified contract for the recovery, so I was unable to find the specific message that they're validating against and the actual recovery snippet that they're using. However, you can find more info about the signing process and on-chain recovery in this answer (the mentioned v, r and s params are literally parts of the whole signature).
I'm learning Dart and Flutter, and I'm finding it a mostly pleasureable experience. I'm making an app that I want to communicate with Amazon AWS resources. However, I'm stuck with an issue that I haven't been able to resolve for a while now.
I'm making a function for getting keys and tokens necessary for making authenticated requests to the API at AWS. I'm using a library function from AWS Amplify to get an AuthSession object. If I set a breakpoint to just after the AuthSession object has been retrieved, it seems as if this object contains some object called AuthSession.credentials. This in turn contains awsAccessKey, awsSecretKey and sessionToken, which are the tokens and keys that I need. I can access them in the debug console when execution is paused.
Future<AWSCredentials> getAWSCredentials() async {
final AuthSession authSession = await Amplify.Auth.fetchAuthSession(
options: CognitoSessionOptions(getAWSCredentials: true));
final a = 1; // I set a breakpoint on this line
//final AWSCredentials awsCredentials = authSession.credentials;
//return awsCredentials;
}
VS Code screenshot of objects in scope at breakpoint
However, if I try to make the function return this AuthSession (by uncommenting the last two lines of the above function), or one of the tokens directly, it doesn't compile anymore and I get the error message
The getter 'credentials' isn't defined for the type 'AuthSession'.
Try importing the library that defines 'credentials', correcting the name to the name of an existing getter, or defining a getter or field named 'credentials'. dart(undefined_getter)
I tried to dig into the code defining the class AuthSession, and it doesn't seem to contain any reference to the credentials object. However, it's obviously there at runtime. Why can't I access it?
The class AuthSession does not contain any member called credentials, so when casting the result of fetchAuthSession() to an AuthSession, it is not possible to access that member. However, the subclass CognitoAuthSession does contain the credentials member, so casting the result to that type allows access to authSession.credentials.
So the call to fetchAuthSession() should be
final CognitoAuthSession authSession = await Amplify.Auth.fetchAuthSession(
options: CognitoSessionOptions(getAWSCredentials: true));
I've just deployed a Smart Contract using the ethereum wallet.
I got the Smart Contract address , I copied its ABI from remix and verified it on ethereum wallet,it was active and I could see all its methods.
Then I tried to call it from my nodejs server.I did it,I didn't get any error...
But instead of a classic response like the returned values of the methods below I got mined blocks....and this is very weird I think...
How am I supposed to get the methods output(the returns) ?
After that I tried to deploy another contract,this time a very simple one with the same methods name,smart contract name,parameters but without code inside the methods only a basic hard-coded return.When I deployed this contract as well I got the same mined smart contract address...which is weird,in my opinion...
I've been using 1.0.0-beta.46 , nodejs , expressjs
When I said eth wallet I meant...that website generated with puppeth , on /#wallet page
Here is the basic smart contract I tried to deploy second time.The result was the same as the first smart contract.
pragma solidity >= 0.4.22 < 0.6.0;
contract BasicContract {
function function1(uint16 a,uint16 b,uint16 c,uint16 d) external payable returns(uint256){
//a,b,c,d doesn't matter
return 68;
}
//buy a ticket
function function2(uint128 a,uint16 b) external payable returns(uint128){
//a,b doesn't matter
return 94;
}
function function3(uint128 a) external payable returns(bool){
//a doesn't matter
return false;
}
}
There are two ways to invoke a function in a smart contract: through a transaction sent to the network or via a local call.
Transactions don't have return values. What you get back from the library you use to make the transaction is typically the transaction hash. Any return value from the function you invoked is discarded.
A local call doesn't involve a transaction to the network and thus can't change any state. But it does give you a return value.
Which method is chosen by default for most libraries is based on whether the function is state-changing or not. If you mark your functions as view or pure, it tells the library that those functions don't change state and can then safely be just called locally to get a return value. So a simple "fix" for the above code is to make those functions pure. For functions that do change state, you'll want to switch from using return values to emitting events instead, which can be read after the transaction is mined.
I'm wondering if its possible to load a SSHKey via the Chilkat library without directly knowing the type. Currently I need to do something like this:
BOOL success = false;
if([privateKey FromOpenSshPublicKey: privateKeyString])
{
NSLog(#"key is FromOpenSshPublicKey");
success = true;
}
else if([privateKey FromPuttyPrivateKey: privateKeyString])
{
NSLog(#"key is FromPuttyPrivateKey");
success = true;
}
else if([privateKey FromRfc4716PublicKey: privateKeyString])
{
NSLog(#"key is FromRfc4716PublicKey");
success = true;
}
But it makes logging a bit difficult if I want to use something like LastErrorText.
The methods were originally written to load a key of a specific type. In actuality, all of the methods auto-recognize the type and will still load the key successfully. For example, you may call FromOpenSshPrivate key with a PuTTY private key, and it still works. (you can even pass PEM to it).
However... you do need to know if you have a public or private key. A call to FromPrivateKey will fail if you pass a public key to it. The reason is that the private parts of the key are simply not present, and if you wanted to load a private key it must be that you're doing something that requires a private key.
On the other hand, a public key is just a portion of the full private key. If you have a private key, by definition you also have the public key. (For example, an RSA public key is composed of the modulus and exponent, but an RSA private key contains modulus, exponent, plus other parts. If you have the private key, then you have the modulus and exponent and by definition you also have the public key.) Thus.. passing a private key to a method that loads a public key will still work. You're just passing more than what's necessary.
In the 7nodes example (https://github.com/jpmorganchase/quorum-examples/tree/master/examples/7nodes ) for quorum, the smart contract that is deployed is a private contract between node1 and node7. To make it private the script file author used public key passed by private key."sending of a private transaction to generate a (private) smart contract (SimpleStorage) sent from node 1 "for" node 7 (denoted by the public key passed via privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="] in the sendTransaction call)."
How exactly the key value "ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc=" was generated i could not understand?
Also, after the completion of the JS file script1.js, it gave me the Contract transaction send: TransactionHash", and i never got the contract address.
When will the contract address come after the mining is completed ?
How do i recognise that this address is my smart contract address ?
The keys are already generated for the nodes.
When you spin up the environment, each node is assigned a predefined dummy public keys.
this can be found at location : \quorum-examples\examples\7nodes\keys
In 7Nodes example you can see the 256bit private key in raft/nodekey* files and the corresponding 512bit public key in nodename (enode) text in static-nodes.json. Use bootnode to create private and public key pairs. And use constellation-node to generate .pub and .key files.
To answer the second part of your question, to get the contract address you can use eth.getTransactionReceipt(__); and copy the txHash you get (quoted) into the blank.
Then the contract address should come up in one of the fields returned.
Check out this page for more info/details.
The key used here is the public key of transaction manager which is respobsible for sending and receiving private transactions in addition to encrypting communications. You can find this key in file named tm.pub inside data folder of the node alongside its associated private key in file tm.key.