public static async Task <string> CreateTransaction(Transaction trx) { core.Services.AbiSerializationProvider.Prefix = "VHKD"; var eosConfig = new EosConfigurator() { HttpEndpoint = "http://192.168.1.61", //Mainnet ExpireSeconds = 60, ChainId = "afe97f023511453c09c64f5bb655e7f4dc6694685aff7231219964e9cc521585", SignProvider = new core.Services.DefaultSignProvider("5JNNWKaCoWvN5xojDXsW38Z6uoLmvM9NPh3coQD5z3TgsuY4nmt", "VHKD") }; var api = new EosApi(eosConfig, new HttpHandler()); var abiSerializer = new core.Services.AbiSerializationProvider(api); if (eosConfig.SignProvider == null) { throw new ArgumentNullException("SignProvider"); } GetInfoResponse getInfoResult = null; string chainId = eosConfig.ChainId; if (string.IsNullOrWhiteSpace(chainId)) { getInfoResult = await api.GetInfo(); chainId = getInfoResult.chain_id; } if (trx.expiration == DateTime.MinValue || trx.ref_block_num == 0 || trx.ref_block_prefix == 0) { if (getInfoResult == null) { getInfoResult = await api.GetInfo(); } var getBlockResult = await api.GetBlock(new GetBlockRequest() { block_num_or_id = getInfoResult.last_irreversible_block_num.ToString() }); trx.expiration = getInfoResult.head_block_time.AddSeconds(eosConfig.ExpireSeconds); trx.ref_block_num = (UInt16)(getInfoResult.last_irreversible_block_num & 0xFFFF); trx.ref_block_prefix = getBlockResult.ref_block_prefix; } var packedTrx = await abiSerializer.SerializePackedTransaction(trx); var availableKeys = await eosConfig.SignProvider.GetAvailableKeys(); var requiredKeys = await GetRequiredKeys(api, abiSerializer, availableKeys.ToList(), trx); IEnumerable <string> abis = null; if (trx.actions != null) { abis = trx.actions.Select(a => a.account); } var signatures = await eosConfig.SignProvider.Sign(chainId, requiredKeys, packedTrx, abis); var result = await api.PushTransaction(new PushTransactionRequest() { signatures = signatures.ToArray(), compression = 0, packed_context_free_data = "", packed_trx = SerializationHelper.ByteArrayToHexString(packedTrx) }); return(result.transaction_id); }
private async Task <PushTransactionResponse> CreateTransaction() { var getInfoResult = await DefaultApi.GetInfo(); var getBlockResult = await DefaultApi.GetBlock(new GetBlockRequest() { block_num_or_id = getInfoResult.last_irreversible_block_num.ToString() }); var trx = new Transaction() { //trx headers expiration = getInfoResult.head_block_time.AddSeconds(60), //expire Seconds ref_block_num = (UInt16)(getInfoResult.last_irreversible_block_num & 0xFFFF), ref_block_prefix = getBlockResult.ref_block_prefix, // trx info max_net_usage_words = 0, max_cpu_usage_ms = 0, delay_sec = 0, context_free_actions = new List <Core.Api.v1.Action>(), transaction_extensions = new List <Extension>(), actions = new List <Core.Api.v1.Action>() { new Core.Api.v1.Action() { account = "eosio.token", authorization = new List <PermissionLevel>() { new PermissionLevel() { actor = "tester112345", permission = "active" } }, name = "transfer", data = new Dictionary <string, object>() { { "from", "tester112345" }, { "to", "tester212345" }, { "quantity", "1.0000 EOS" }, { "memo", "hello crypto world!" } } } } }; var abiSerializer = new AbiSerializationProvider(DefaultApi); var packedTrx = await abiSerializer.SerializePackedTransaction(trx); var requiredKeys = new List <string>() { "EOS8Q8CJqwnSsV4A6HDBEqmQCqpQcBnhGME1RUvydDRnswNngpqfr" }; var signatures = await EosConfig.SignProvider.Sign(DefaultApi.Config.ChainId, requiredKeys, packedTrx); return(await DefaultApi.PushTransaction(new PushTransactionRequest() { signatures = signatures.ToArray(), compression = 0, packed_context_free_data = "", packed_trx = SerializationHelper.ByteArrayToHexString(packedTrx) })); }