public static string CalculateContractAddress(string address, BigInteger nonce) { var sha3 = new Sha3Keccack(); return (sha3.CalculateHash(RLP.RLP.EncodeList(RLP.RLP.EncodeElement(address.HexToByteArray()), RLP.RLP.EncodeElement(nonce.ToBytesForRLPEncoding()))).ToHex().Substring(24)); }
public static string CalculateContractAddress(string address, BigInteger nonce) { if (string.IsNullOrEmpty(address)) { throw new System.ArgumentException($"'{nameof(address)}' cannot be null or empty.", nameof(address)); } var sha3 = new Sha3Keccack(); return sha3.CalculateHash(RLP.RLP.EncodeList(RLP.RLP.EncodeElement(address.HexToByteArray()), RLP.RLP.EncodeElement(nonce.ToBytesForRLPEncoding()))).ToHex().Substring(24).ConvertToEthereumChecksumAddress(); }
public TransactionInput CreateSetTopScoreTransactionInput(string addressFrom, string addressOwner, string privateKey, BigInteger score, HexBigInteger gas = null, HexBigInteger valueAmount = null) { var numberBytes = new IntTypeEncoder().Encode(score); var sha3 = new Nethereum.Util.Sha3Keccack(); var hash = sha3.CalculateHashFromHex(addressFrom, addressOwner, numberBytes.ToHex()); var signer = new MessageSigner(); var signature = signer.Sign(hash.HexToByteArray(), privateKey); var ethEcdsa = MessageSigner.ExtractEcdsaSignature(signature); var function = GetFunctionSetTopScore(); return(function.CreateTransactionInput(addressFrom, gas, valueAmount, score, ethEcdsa.V, ethEcdsa.R, ethEcdsa.S)); }
public TransactionInput closeRoomInput(string addressFrom, string privateKey, HexBigInteger gas, int id, HexBigInteger valueAmount = null) { var numberBytes = new IntTypeEncoder().Encode(id); var sha3 = new Nethereum.Util.Sha3Keccack(); var hash = sha3.CalculateHashFromHex(addressFrom, numberBytes.ToHex()); var signer = new MessageSigner(); var signature = signer.Sign(hash.HexToByteArray(), privateKey); var ethEcdsa = MessageSigner.ExtractEcdsaSignature(signature); object[] array = new object[] { id }; var function = closeRoomFunction(); return(function.CreateTransactionInput(addressFrom, gas, valueAmount, array)); }
public TransactionInput createUserInput(string addressFrom, string privateKey, HexBigInteger gas, string name, int pin) { var stringBytes = new StringTypeEncoder().Encode(name); var numberBytes = new IntTypeEncoder().Encode(pin); var sha3 = new Nethereum.Util.Sha3Keccack(); var hash = sha3.CalculateHashFromHex(addressFrom, numberBytes.ToHex(), stringBytes.ToHex()); var signer = new MessageSigner(); var signature = signer.Sign(hash.HexToByteArray(), privateKey); var ethEcdsa = MessageSigner.ExtractEcdsaSignature(signature); object[] array = new object[] { name, pin }; var function = createUserFunction(); return(function.CreateTransactionInput(addressFrom, array)); }
public bool IsChecksumAddress(string address) { address = address.RemoveHexPrefix(); var addressHash = new Sha3Keccack().CalculateHash(address.ToLower()); for (var i = 0; i < 40; i++) { var value = int.Parse(addressHash[i].ToString(), NumberStyles.HexNumber); // the nth letter should be uppercase if the nth digit of casemap is 1 if (value > 7 && address[i].ToString().ToUpper() != address[i].ToString() || value <= 7 && address[i].ToString().ToLower() != address[i].ToString()) { return(false); } } return(true); }
public string ConvertToChecksumAddress(string address) { address = address.ToLower().RemoveHexPrefix(); var addressHash = new Sha3Keccack().CalculateHash(address); var checksumAddress = "0x"; for (var i = 0; i < address.Length; i++) { if (int.Parse(addressHash[i].ToString(), NumberStyles.HexNumber) > 7) { checksumAddress += address[i].ToString().ToUpper(); } else { checksumAddress += address[i]; } } return(checksumAddress); }
public static string CalculateCreate2Address(string address, string saltHex, string byteCodeHex) { if (string.IsNullOrEmpty(address)) { throw new System.ArgumentException($"'{nameof(address)}' cannot be null or empty.", nameof(address)); } if (string.IsNullOrEmpty(saltHex)) { throw new System.ArgumentException($"'{nameof(saltHex)}' cannot be null or empty.", nameof(saltHex)); } if(saltHex.EnsureHexPrefix().Length != 66) { throw new System.ArgumentException($"'{nameof(saltHex)}' needs to be 32 bytes", nameof(saltHex)); } var sha3 = new Sha3Keccack(); return sha3.CalculateHashFromHex("0xff", address, saltHex, sha3.CalculateHashFromHex(byteCodeHex)).Substring(24).ConvertToEthereumChecksumAddress(); }
public static string CalculateTransactionHash(string rawSignedTransaction) { var sha3 = new Sha3Keccack(); return(sha3.CalculateHashFromHex(rawSignedTransaction)); }