// Code Example: Docs / Recipe / Crypto / Creeate Account static async Task Main(string[] args) { // For Example: var gatewayUrl = args[0]; // 2.testnet.hedera.com:50211 var gatewayAccountNo = long.Parse(args[1]); // 5 (gateway node 0.0.5) var payerAccountNo = long.Parse(args[2]); // 20 (account 0.0.20) var payerPrivateKey = Hex.ToBytes(args[3]); // 302e0201... (48 byte Ed25519 private in hex) var newPublicKey = Hex.ToBytes(args[4]); // 302a3005... (44 byte Ed25519 public in hex) var initialBalance = ulong.Parse(args[5]); // 100_000_000 (1ℏ initial balance) try { await using var client = new Client(ctx => { ctx.Gateway = new Gateway(gatewayUrl, 0, 0, gatewayAccountNo); ctx.Payer = new Address(0, 0, payerAccountNo); ctx.Signatory = new Signatory(payerPrivateKey); }); var createParams = new CreateAccountParams { Endorsement = new Endorsement(newPublicKey), InitialBalance = initialBalance }; var account = await client.CreateAccountAsync(createParams); var address = account.Address; Console.WriteLine($"New Account ID: {address.ShardNum}.{address.RealmNum}.{address.AccountNum}"); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); Console.Error.WriteLine(ex.StackTrace); } }
/// <summary> /// /// </summary> /// <param name="imAccount"></param> /// <returns></returns> public bool ChangeNickname(ThirdIMAccount imAccount) { if (false == this.LoadAccessToken()) { return(false); } var changeAccountUrl = string.Format(ChangeAccountApi, this.OrgName, this.AppName, imAccount.PlatformAccountId); var data = new CreateAccountParams() { Nickname = imAccount.Nickname }; var tokenResponse = HttpJson(HttpDecorator.HttpMethod.PUT, changeAccountUrl, data); if (IsErrorResult(tokenResponse.Content)) { LogManager.GetLogger().Error("Easemob-Error(ChangeNickname): {0}[{1},{2}] => {3}", changeAccountUrl, this.AccessToken, imAccount.PlatformAccountId, tokenResponse.Content); return(false); } else { LogManager.GetLogger().Info("Easemob-Result(ChangeNickname): {0}[{1},{2}] => {3}", changeAccountUrl, this.AccessToken, imAccount.PlatformAccountId, tokenResponse.Content); return(true); } }
internal static Proto.Key KeysFromEndorsements(CreateAccountParams createParameters) { if (createParameters is null) { throw new ArgumentNullException(nameof(createParameters), "The create parameters are missing. Please check that the argument is not null."); } if (createParameters.Endorsement is null) { throw new ArgumentOutOfRangeException(nameof(createParameters), "The Endorsement for the account is missing, it is required."); } return(new Proto.Key(createParameters.Endorsement)); }
protected async Task HandleValidSubmit() { _output = null; await _network.ExecuteAsync(_input.Gateway, _input.Payer, async client => { var createParams = new CreateAccountParams { Endorsement = _input.Endorsement, InitialBalance = (ulong)_input.InitialBalance.GetValueOrDefault(), RequireReceiveSignature = _input.RequireReceiveSignature, Proxy = _input.Proxy }; _output = await client.CreateAccountAsync(createParams, ctx => ctx.Memo = _input.Memo?.Trim()); }); }
public async Task <CreateAccountResult> CreateAccount(CreateAccountParams createParams) { var parameters = new DynamicParameters(); parameters.Add("@userId", createParams.UserId, DbType.Int64); parameters.Add("@employerNumber", createParams.EmployerNumber, DbType.String); parameters.Add("@employerName", createParams.EmployerName, DbType.String); parameters.Add("@employerRegisteredAddress", createParams.EmployerRegisteredAddress, DbType.String); parameters.Add("@employerDateOfIncorporation", createParams.EmployerDateOfIncorporation, DbType.DateTime); parameters.Add("@employerRef", createParams.EmployerRef, DbType.String); parameters.Add("@accountId", null, DbType.Int64, ParameterDirection.Output, 8); parameters.Add("@legalentityId", null, DbType.Int64, ParameterDirection.Output, 8); parameters.Add("@accountLegalentityId", null, DbType.Int64, ParameterDirection.Output, 8); parameters.Add("@employerAgreementId", null, DbType.Int64, ParameterDirection.Output, 8); parameters.Add("@accessToken", createParams.AccessToken, DbType.String); parameters.Add("@refreshToken", createParams.RefreshToken, DbType.String); parameters.Add("@addedDate", DateTime.UtcNow, DbType.DateTime); parameters.Add("@employerRefName", createParams.EmployerRefName, DbType.String); parameters.Add("@status", createParams.CompanyStatus); parameters.Add("@source", createParams.Source); parameters.Add("@publicSectorDataSource", createParams.PublicSectorDataSource); parameters.Add("@sector", createParams.Sector, DbType.String); parameters.Add("@aorn", createParams.Aorn, DbType.String); parameters.Add("@agreementType", createParams.AgreementType, DbType.Int16); parameters.Add("@apprenticeshipEmployerType", createParams.ApprenticeshipEmployerType, DbType.Int16); parameters.Add("@agreementVersion", null, DbType.Int32, ParameterDirection.Output); await _db.Value.Database.Connection.ExecuteAsync( sql : "[employer_account].[CreateAccount]", param : parameters, transaction : _db.Value.Database.CurrentTransaction.UnderlyingTransaction, commandType : CommandType.StoredProcedure); var accountLegalEntityId = parameters.Get <long>("@accountLegalentityId"); await UpdateAccountLegalEntityPublicHashedIdInternal(_db.Value.Database.Connection, _db.Value.Database.CurrentTransaction.UnderlyingTransaction, accountLegalEntityId); return(new CreateAccountResult { AccountId = parameters.Get <long>("@accountId"), LegalEntityId = parameters.Get <long>("@legalentityId"), EmployerAgreementId = parameters.Get <long>("@employerAgreementId"), AgreementVersion = parameters.Get <int>("@agreementVersion"), AccountLegalEntityId = accountLegalEntityId }); }
/// <summary> /// Creates a new network account with a given initial balance /// and other values as indicated in the create parameters. /// </summary> /// <param name="createParameters"> /// The account creation parameters, includes the initial balance, /// public key and values associated with the new account. /// </param> /// <param name="configure"> /// Optional callback method providing an opportunity to modify /// the execution configuration for just this method call. /// It is executed prior to submitting the request to the network. /// </param> /// <returns> /// A transaction record with a description of the newly created account /// and record information. /// </returns> /// <exception cref="ArgumentOutOfRangeException">If required arguments are missing.</exception> /// <exception cref="InvalidOperationException">If required context configuration is missing.</exception> /// <exception cref="PrecheckException">If the gateway node create rejected the request upon submission.</exception> /// <exception cref="ConsensusException">If the network was unable to come to consensus before the duration of the transaction expired.</exception> /// <exception cref="TransactionException">If the network rejected the create request as invalid or had missing data.</exception> public async Task <CreateAccountRecord> CreateAccountWithRecordAsync(CreateAccountParams createParameters, Action <IContext>?configure = null) { return(new CreateAccountRecord(await ExecuteTransactionAsync(new CryptoCreateTransactionBody(createParameters), configure, true, createParameters.Signatory).ConfigureAwait(false))); }