主頁 > 區塊鏈 > 使用Java+Web3j和Ethereum網路互動(二):部署ERC20并呼叫合約功能

使用Java+Web3j和Ethereum網路互動(二):部署ERC20并呼叫合約功能

2022-07-12 18:03:43 區塊鏈

添加web3j-maven-plugin

web3j-maven-plugin是一個maven插件,可以直接將solidity檔案編譯為檔案Java,方便Java開發者直接進行合約的部署,加載,呼叫,
我們直接將該插件添加到maven的pom.xml檔案中即可,

<plugin>
	<groupId>org.web3j</groupId>
	<artifactId>web3j-maven-plugin</artifactId>
	<version>4.8.7</version>
	<configuration>
                <!-- 指定Java版智能合約生成的位置 -->
		<packageName>org.newonexd.ethereumclient.smartContract</packageName>
		<soliditySourceFiles>
                        <!-- solidity源檔案放置位置 -->
			<directory>src/main/resources/solc</directory>
			<includes>
                                <!-- 只將后綴為.sol的檔案包括進去 -->
				<include>**/*.sol</include>
			</includes>
		</soliditySourceFiles>
		<outputDirectory>
			<java>src/main/java</java>
		</outputDirectory>
	</configuration>
</plugin>

具體檔案位置如下圖所示:
專案結構

編譯solidity檔案到Java檔案

本文以ERC20.sol檔案為例,將該檔案放置在src/main/resources/solc檔案夾內.Erc20.sol檔案將在檔案末尾貼出,
然后打開命令列定位到當前pom.xml檔案所在檔案夾,執行以下命令:

mvn web3j:generate-sources

輸出以下資訊說明編譯成功:

[INFO]  Built Class for contract 'ERC20'
[INFO] No abiSourceFiles directory specified, using default directory [src/main/resources]
[INFO] No abiSourceFiles contracts specified, using the default [**/*.json]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.841 s
[INFO] Finished at: 2022-06-26T11:16:47+08:00
[INFO] ------------------------------------------------------------------------

此時在org.newonexd.ethereumclient.smartContract檔案夾中可以看到生成的Java版智能合約檔案,

與以太坊進行合約互動

部署合約

在以太坊部署合約需要有一個賬戶,我們通過web3j把賬戶加載進來:

private static final Credentials credentials;

    static{
        //根據私鑰創建Java賬戶類
        credentials = Credentials.create("0x534d8d93a5ef66147e2462682bc524ef490898010a1550955314ffea5f0a8959");
    }

我們可以根據私鑰加載賬戶,或者web3j提供了其他方案如ECKeyPair進行賬戶的加載,
賬戶加載成功后,我們也可以直接與以太坊互動查詢Ether余額:

    @GetMapping("/ether")
    public BigInteger doGetEther()throws Exception{
        //獲取最新的區塊號
        BigInteger blockNumber = web3j.ethBlockNumber().sendAsync().get().getBlockNumber();
        logger.info("The BlockNumber is: {}",blockNumber);
        //生成請求引數
        DefaultBlockParameterNumber defaultBlockParameterNumber = new DefaultBlockParameterNumber(blockNumber);
        //根據請求引數獲取余額
        EthGetBalance ethGetBalance  = web3j.ethGetBalance(credentials.getAddress(),defaultBlockParameterNumber)
                .sendAsync().get();
        logger.info("Get Account Ether is: {}",ethGetBalance.getBalance());
        return ethGetBalance.getBalance();
    }

接下來我們進行合約在以太坊上面的部署:

ERC20 contract = ERC20.deploy(web3j,credentials, ERC20.GAS_PRICE,ERC20.GAS_LIMIT,coinName, BigInteger.valueOf(coinTotal),symbol).sendAsync().get();

credentials是我們剛剛加載的賬戶資訊,也是合約部署者,coinName是合約中Token名稱,coinTotal為Token發行量,symbol為Token簡稱,
僅一行代碼,我們就可以把合約部署到以太坊上面了,

加載合約

部署完成以后,我們可以直接進行合約的呼叫,但不能每次呼叫合約都對合約進行部署一遍,因此web3j提供了加載合約資訊的功能,我們通過合約地址將合約加載到Java程式中,也可以進行合約的呼叫,具體的加載方法如下:

ERC20.load(contractAddress,web3j,credentials,ERC20.GAS_PRICE,ERC20.GAS_LIMIT);

合約加載成功后,我們同樣可以進行合約的呼叫了,

呼叫合約

具體可以呼叫合約哪些功能,則是根據智能合約中定義的方法而定了,本文僅列出部分幾個功能,

查詢發行量

ERC20 erc20 = loadContract(contractAddress);
BigInteger coinTotal = erc20.totalSupply().sendAsync().get();

查詢指定賬戶地址下Token數量

ERC20 erc20 = loadContract(contractAddress);
BigInteger balance = erc20.balanceOf(accountAddress).sendAsync().get();

轉賬

ERC20 erc20 = loadContract(contractAddress);
TransactionReceipt transactionReceipt = erc20.transfer(contractAddress,BigInteger.valueOf(tokenValue)).sendAsync().get();

授權他人賬戶一定數量的Token

ERC20 erc20 = loadContract(contractAddress);
TransactionReceipt transactionReceipt = erc20.approve(approveAddress,BigInteger.valueOf(tokenValue)).sendAsync().get();

查詢他人授權當前賬戶的Token數量

ERC20 erc20 = loadContract(contractAddress);
BigInteger allowrance = erc20.allowance(credentials.getAddress(),approveAddress).sendAsync().get();

Erc20源代碼

Erc20 token的代碼在網路上比較容易找到,官方也有提供,這里列出一份簡單的代碼:

pragma solidity ^0.4.24;

/**
 * @title SafeMath
 * @dev Math operations with safety checks that revert on error
 */
library SafeMath {
  /**
  * @dev Multiplies two numbers, reverts on overflow.
  */
  function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
    // benefit is lost if 'b' is also tested.
    // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
    if (a == 0) {
      return 0;
    }
    uint256 c = a * b;
    require(c / a == b);
    return c;
  }
  /**
  * @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
  */
  function div(uint256 a, uint256 b) internal pure returns (uint256) {
    require(b > 0); // Solidity only automatically asserts when dividing by 0
    uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return c;
  }
  /**
  * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
  */
  function sub(uint256 a, uint256 b) internal pure returns (uint256) {
    require(b <= a);
    uint256 c = a - b;
    return c;
  }
  /**
  * @dev Adds two numbers, reverts on overflow.
  */
  function add(uint256 a, uint256 b) internal pure returns (uint256) {
    uint256 c = a + b;
    require(c >= a);
    return c;
  }
  /**
  * @dev Divides two numbers and returns the remainder (unsigned integer modulo),
  * reverts when dividing by zero.
  */
  function mod(uint256 a, uint256 b) internal pure returns (uint256) {
    require(b != 0);
    return a % b;
  }
}
/**
 * @title ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/20
 */
interface IERC20 {
  function totalSupply() external view returns (uint256);
  function balanceOf(address who) external view returns (uint256);
  function allowance(address owner, address spender)
    external view returns (uint256);
  function transfer(address to, uint256 value) external returns (bool);
  function approve(address spender, uint256 value)
    external returns (bool);
  function transferFrom(address from, address to, uint256 value)
    external returns (bool);
  event Transfer(
    address indexed from,
    address indexed to,
    uint256 value
  );
  event Approval(
    address indexed owner,
    address indexed spender,
    uint256 value
  );
}
/**
 * @title Standard ERC20 token
 *
 * @dev Implementation of the basic standard token.
 * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
 * Originally based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
 */
contract ERC20 is IERC20 {
  using SafeMath for uint256;
  mapping (address => uint256) private _balances;
  mapping (address => mapping (address => uint256)) private _allowed;
  uint256 private _totalSupply;
  string private _coinName;
  string private _symbol;
  uint256 private _decimals = 18;
  constructor(string coinName,uint256 totalSupply,string symbol)public{
      _coinName = coinName;
      _symbol = symbol;
      _totalSupply = totalSupply * 10 ** uint256(_decimals);
      _balances[msg.sender] = _totalSupply;
  }
  function coinName()public view returns(string){
      return _coinName;
  }


  /**
  * @dev Total number of tokens in existence
  */
  function totalSupply() public view returns (uint256) {
    return _totalSupply;
  }
  /**
  * @dev Gets the balance of the specified address.
  * @param owner The address to query the balance of.
  * @return An uint256 representing the amount owned by the passed address.
  */
  function balanceOf(address owner) public view returns (uint256) {
    return _balances[owner];
  }
  /**
   * @dev Function to check the amount of tokens that an owner allowed to a spender.
   * @param owner address The address which owns the funds.
   * @param spender address The address which will spend the funds.
   * @return A uint256 specifying the amount of tokens still available for the spender.
   */
  function allowance(
    address owner,
    address spender
   )
    public
    view
    returns (uint256)
  {
    return _allowed[owner][spender];
  }
  /**
  * @dev Transfer token for a specified address
  * @param to The address to transfer to.
  * @param value The amount to be transferred.
  */
  function transfer(address to, uint256 value) public returns (bool) {
    require(value <= _balances[msg.sender]);
    require(to != address(0));
    _balances[msg.sender] = _balances[msg.sender].sub(value);
    _balances[to] = _balances[to].add(value);
    emit Transfer(msg.sender, to, value);
    return true;
  }
  /**
   * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
   * Beware that changing an allowance with this method brings the risk that someone may use both the old
   * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
   * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
   * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
   * @param spender The address which will spend the funds.
   * @param value The amount of tokens to be spent.
   */
  function approve(address spender, uint256 value) public returns (bool) {
    require(spender != address(0));
    _allowed[msg.sender][spender] = value;
    emit Approval(msg.sender, spender, value);
    return true;
  }
  /**
   * @dev Transfer tokens from one address to another
   * @param from address The address which you want to send tokens from
   * @param to address The address which you want to transfer to
   * @param value uint256 the amount of tokens to be transferred
   */
  function transferFrom(
    address from,
    address to,
    uint256 value
  )
    public
    returns (bool)
  {
    require(value <= _balances[from]);
    require(value <= _allowed[from][msg.sender]);
    require(to != address(0));
    _balances[from] = _balances[from].sub(value);
    _balances[to] = _balances[to].add(value);
    _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
    emit Transfer(from, to, value);
    return true;
  }
  /**
   * @dev Increase the amount of tokens that an owner allowed to a spender.
   * approve should be called when allowed_[_spender] == 0. To increment
   * allowed value is better to use this function to avoid 2 calls (and wait until
   * the first transaction is mined)
   * From MonolithDAO Token.sol
   * @param spender The address which will spend the funds.
   * @param addedValue The amount of tokens to increase the allowance by.
   */
  function increaseAllowance(
    address spender,
    uint256 addedValue
  )
    public
    returns (bool)
  {
    require(spender != address(0));
    _allowed[msg.sender][spender] = (
      _allowed[msg.sender][spender].add(addedValue));
    emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
    return true;
  }
  /**
   * @dev Decrease the amount of tokens that an owner allowed to a spender.
   * approve should be called when allowed_[_spender] == 0. To decrement
   * allowed value is better to use this function to avoid 2 calls (and wait until
   * the first transaction is mined)
   * From MonolithDAO Token.sol
   * @param spender The address which will spend the funds.
   * @param subtractedValue The amount of tokens to decrease the allowance by.
   */
  function decreaseAllowance(
    address spender,
    uint256 subtractedValue
  )
    public
    returns (bool)
  {
    require(spender != address(0));
    _allowed[msg.sender][spender] = (
      _allowed[msg.sender][spender].sub(subtractedValue));
    emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
    return true;
  }
  /**
   * @dev Internal function that mints an amount of the token and assigns it to
   * an account. This encapsulates the modification of balances such that the
   * proper events are emitted.
   * @param account The account that will receive the created tokens.
   * @param amount The amount that will be created.
   */
  function _mint(address account, uint256 amount) internal {
    require(account != 0);
    _totalSupply = _totalSupply.add(amount);
    _balances[account] = _balances[account].add(amount);
    emit Transfer(address(0), account, amount);
  }
  /**
   * @dev Internal function that burns an amount of the token of a given
   * account.
   * @param account The account whose tokens will be burnt.
   * @param amount The amount that will be burnt.
   */
  function _burn(address account, uint256 amount) internal {
    require(account != 0);
    require(amount <= _balances[account]);
    _totalSupply = _totalSupply.sub(amount);
    _balances[account] = _balances[account].sub(amount);
    emit Transfer(account, address(0), amount);
  }
  /**
   * @dev Internal function that burns an amount of the token of a given
   * account, deducting from the sender's allowance for said account. Uses the
   * internal burn function.
   * @param account The account whose tokens will be burnt.
   * @param amount The amount that will be burnt.
   */
  function _burnFrom(address account, uint256 amount) internal {
    require(amount <= _allowed[account][msg.sender]);
    // Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
    // this function needs to emit an event with the updated approval.
    _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(
      amount);
    _burn(account, amount);
  }
}

本文原始碼

/**
 * @description erc20控制器
 * @author newonexd
 * @date 2022/6/22 21:44
 */
@RestController
@RequestMapping("erc20")
public class Erc20Controller {
    private static final Logger logger = LoggerFactory.getLogger(Erc20Controller.class);


    @Autowired
    private Web3j web3j;

    private static final Credentials credentials;

    static{
        //根據私鑰創建Java賬戶類
        credentials = Credentials.create("0x534d8d93a5ef66147e2462682bc524ef490898010a1550955314ffea5f0a8959");
    }

    /**
     * @description 獲取該賬戶下的Ether總數
     * @author newonexd
     * @date 2022/6/22 21:34
     * @return BigInteger
     */
    @GetMapping("/ether")
    public BigInteger doGetEther()throws Exception{
        //獲取最新的區塊號
        BigInteger blockNumber = web3j.ethBlockNumber().sendAsync().get().getBlockNumber();
        logger.info("The BlockNumber is: {}",blockNumber);
        //生成請求引數
        DefaultBlockParameterNumber defaultBlockParameterNumber = new DefaultBlockParameterNumber(blockNumber);
        //根據請求引數獲取余額
        EthGetBalance ethGetBalance  = web3j.ethGetBalance(credentials.getAddress(),defaultBlockParameterNumber)
                .sendAsync().get();
        logger.info("Get Account Ether is: {}",ethGetBalance.getBalance());
        return ethGetBalance.getBalance();
    }

    /**
     * @description 部署Erc20 合約
     * @author newonexd
     * @date 2022/6/22 21:34
     * @param coinName  Erc20Token 名稱
     * @param symbol  Erc20Token 簡寫
     * @param coinTotal 總發行量
     * @return String 合約地址
     */
    @PostMapping("/deployErc20")
    public String doDeployErc20(@RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/coinName")String coinName,
                                @RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/symbol")String symbol,
                                @RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/coinTotal")Long coinTotal)throws Exception{
        ERC20 contract = ERC20.deploy(web3j,credentials, ERC20.GAS_PRICE,ERC20.GAS_LIMIT,coinName, BigInteger.valueOf(coinTotal),symbol).sendAsync().get();
        logger.info("ERC20 Contract Address: {}",contract.getContractAddress());
        return contract.getContractAddress();
    }


    /**
     * @description 查詢總發行量
     * @author newonexd
     * @date 2022/6/22 21:35
     * @param contractAddress 部署的合約地址
     * @return BigInteger  總發行量
     */
    @GetMapping("/coinTotal")
    public BigInteger getTotal(@RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/contractAddress")String contractAddress) throws Exception {
        ERC20 erc20 = loadContract(contractAddress);
        BigInteger coinTotal = erc20.totalSupply().sendAsync().get();
        logger.info("CoinTotal is: {}",coinTotal);
        return coinTotal;
    }


    /**
     * @description 獲取賬戶下Erc20Token總量
     * @author newonexd
     * @date 2022/6/22 21:36
     * @param contractAddress 合約地址
     * @param accountAddress 賬戶地址
     * @return BigInteger Erc20Token總量
     */
    @GetMapping("/balance")
    public BigInteger getBalance(@RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/contractAddress")String contractAddress,
                                 @RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/accountAddress")String accountAddress) throws Exception {
        ERC20 erc20 = loadContract(contractAddress);
        BigInteger balance = erc20.balanceOf(accountAddress).sendAsync().get();
        logger.info("AccountAddress: {} hava Balance: {}",accountAddress,balance);
        return balance;
    }


    /**
     * @description 授權他人賬戶地址一定數量的Erc20Token 幣
     * @author newonexd
     * @date 2022/6/22 21:36
     * @param contractAddress  合約地址
     * @param approveAddress  被授權的賬戶地址
     * @param tokenValue  授權Token總數
     * @return String 該筆交易的哈希值
     */
    @PostMapping("/approver")
    public String doApprover(@RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/contractAddress")String contractAddress,
                             @RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/approveAddress")String approveAddress,
                             @RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/tokenValue")int tokenValue)throws Exception {
        ERC20 erc20 = loadContract(contractAddress);
        TransactionReceipt transactionReceipt = erc20.approve(approveAddress,BigInteger.valueOf(tokenValue)).sendAsync().get();
        boolean result = transactionReceipt.isStatusOK();
        String transactionHash = transactionReceipt.getTransactionHash();
        logger.info("Approve result: {},TxHash: {}",result,transactionHash);
        return transactionHash;
    }

    /**
     * @description 查詢指定地址下被允許消費的Erc20Token數量
     * @author newonexd
     * @date 2022/6/22 21:37
     * @param contractAddress 合約地址
     * @param tokenValue token數量
     * @return BigInteger 被授權消費的Erc20數量
     */
    @PostMapping("/transfer")
    public int doPostTransfer(@RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/contractAddress")String contractAddress,
                                     @RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/tokenValue")int tokenValue) throws Exception {
        ERC20 erc20 = loadContract(contractAddress);
        TransactionReceipt transactionReceipt = erc20.transfer(contractAddress,BigInteger.valueOf(tokenValue)).sendAsync().get();
        if(transactionReceipt.isStatusOK()){
            logger.info("Transfer token value : {}",tokenValue);
            return tokenValue;
        }else{
            return 0;
        }
    }
    /**
     * @description 查詢指定地址下被允許消費的Erc20Token數量
     * @author newonexd
     * @date 2022/6/22 21:37
     * @param contractAddress 合約地址
     * @param approveAddress 被授權的賬戶地址
     * @return BigInteger 被授權消費的Erc20數量
     */
    @GetMapping("/allowrance")
    public BigInteger doGetAllowrance(@RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/contractAddress")String contractAddress,
                                      @RequestParam(value = "https://www.cnblogs.com/cbkj-xd/p/approveAddress")String approveAddress) throws Exception {
        ERC20 erc20 = loadContract(contractAddress);
        BigInteger allowrance = erc20.allowance(credentials.getAddress(),approveAddress).sendAsync().get();
        logger.info("Allowrance : {}",allowrance);
        return allowrance;
    }

    /**
     * @description 根據合約地址加載合約資訊
     * @author newonexd
     * @date 2022/6/26 11:41
     * @param contractAddress 合約地址
     * @return ERC20
     */
    private ERC20 loadContract(String contractAddress){
        return ERC20.load(contractAddress,web3j,credentials,ERC20.GAS_PRICE,ERC20.GAS_LIMIT);
    }
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/498622.html

標籤:區塊鏈

上一篇:使用Java+Web3j和Ethereum網路互動(一):獲取Ethereum資訊

下一篇:ERC20介紹

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • JAVA使用 web3j 進行token轉賬

    最近新學習了下區塊鏈這方面的知識,所學不多,給大家分享下。 # 1. 關于web3j web3j是一個高度模塊化,反應性,型別安全的Java和Android庫,用于與智能合約配合并與以太坊網路上的客戶端(節點)集成。 # 2. 準備作業 jdk版本1.8 引入maven <dependency> < ......

    uj5u.com 2020-09-10 03:03:06 more
  • 以太坊智能合約開發框架Truffle

    前言 部署智能合約有多種方式,命令列的瀏覽器的渠道都有,但往往跟我們程式員的風格不太相符,因為我們習慣了在IDE里寫了代碼然后打包運行看效果。 雖然現在IDE中已經存在了Solidity插件,可以撰寫智能合約,但是部署智能合約卻要另走他路,沒辦法進行一個快捷的部署與測驗。 如果團隊管理的區塊節點多、 ......

    uj5u.com 2020-09-10 03:03:12 more
  • 谷歌二次驗證碼成為區塊鏈專用安全碼,你怎么看?

    前言 谷歌身份驗證器,前些年大家都比較陌生,但隨著國內互聯網安全的加強,它越來越多地出現在大家的視野中。 比較廣泛接觸的人群是國際3A游戲愛好者,游戲盜號現象嚴重+國外賬號安全應用廣泛,這類游戲一般都會要求用戶系結名為“兩步驗證”、“雙重驗證”等,平臺一般都推薦用谷歌身份驗證器。 后來區塊鏈業務風靡 ......

    uj5u.com 2020-09-10 03:03:17 more
  • 密碼學DAY1

    目錄 ##1.1 密碼學基本概念 密碼在我們的生活中有著重要的作用,那么密碼究竟來自何方,為何會產生呢? 密碼學是網路安全、資訊安全、區塊鏈等產品的基礎,常見的非對稱加密、對稱加密、散列函式等,都屬于密碼學范疇。 密碼學有數千年的歷史,從最開始的替換法到如今的非對稱加密演算法,經歷了古典密碼學,近代密 ......

    uj5u.com 2020-09-10 03:03:50 more
  • 密碼學DAY1_02

    目錄 ##1.1 ASCII編碼 ASCII(American Standard Code for Information Interchange,美國資訊交換標準代碼)是基于拉丁字母的一套電腦編碼系統,主要用于顯示現代英語和其他西歐語言。它是現今最通用的單位元組編碼系統,并等同于國際標準ISO/IE ......

    uj5u.com 2020-09-10 03:04:50 more
  • 密碼學DAY2

    ##1.1 加密模式 加密模式:https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html ECB ECB : Electronic codebook, 電子密碼本. 需要加密的訊息按照塊密碼的塊大小被分為數個塊,并對每個塊進 ......

    uj5u.com 2020-09-10 03:05:42 more
  • NTP時鐘服務器的特點(京準電子)

    NTP時鐘服務器的特點(京準電子) NTP時鐘服務器的特點(京準電子) 京準電子官V——ahjzsz 首先對時間同步進行了背景介紹,然后討論了不同的時間同步網路技術,最后指出了建立全球或區域時間同步網存在的問題。 一、概 述 在通信領域,“同步”概念是指頻率的同步,即網路各個節點的時鐘頻率和相位同步 ......

    uj5u.com 2020-09-10 03:05:47 more
  • 標準化考場時鐘同步系統推進智能化校園建設

    標準化考場時鐘同步系統推進智能化校園建設 標準化考場時鐘同步系統推進智能化校園建設 安徽京準電子科技官微——ahjzsz 一、背景概述隨著教育事業的快速發展,學校建設如雨后春筍,隨之而來的學校教育、管理、安全方面的問題成了學校管理人員面臨的最大的挑戰,這些問題同時也是學生家長所擔心的。為了讓學生有更 ......

    uj5u.com 2020-09-10 03:05:51 more
  • 位元幣入門

    引言 位元幣基本結構 位元幣基礎知識 1)哈希演算法 2)非對稱加密技術 3)數字簽名 4)MerkleTree 5)哪有位元幣,有的是UTXO 6)位元幣挖礦與共識 7)區塊驗證(共識) 總結 引言 上一篇我們已經知道了什么是區塊鏈,此篇說一下區塊鏈的第一個應用——位元幣。其實先有位元幣,后有的區塊 ......

    uj5u.com 2020-09-10 03:06:15 more
  • 北斗對時服務器(北斗對時設備)電力系統應用

    北斗對時服務器(北斗對時設備)電力系統應用 北斗對時服務器(北斗對時設備)電力系統應用 京準電子科技官微(ahjzsz) 中國北斗衛星導航系統(英文名稱:BeiDou Navigation Satellite System,簡稱BDS),因為是目前世界范圍內唯一可以大面積提供免費定位服務的系統,所以 ......

    uj5u.com 2020-09-10 03:06:20 more
最新发布
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:46:47 more
  • Hyperledger Fabric 使用 CouchDB 和復雜智能合約開發

    在上個實驗中,我們已經實作了簡單智能合約實作及客戶端開發,但該實驗中智能合約只有基礎的增刪改查功能,且其中的資料管理功能與傳統 MySQL 比相差甚遠。本文將在前面實驗的基礎上,將 Hyperledger Fabric 的默認資料庫支持 LevelDB 改為 CouchDB 模式,以實作更復雜的資料... ......

    uj5u.com 2023-04-16 07:28:31 more
  • .NET Core 波場鏈離線簽名、廣播交易(發送 TRX和USDT)筆記

    Get Started NuGet You can run the following command to install the Tron.Wallet.Net in your project. PM> Install-Package Tron.Wallet.Net 配置 public reco ......

    uj5u.com 2023-04-14 08:08:00 more
  • DKP 黑客分析——不正確的代幣對比率計算

    概述: 2023 年 2 月 8 日,針對 DKP 協議的閃電貸攻擊導致該協議的用戶損失了 8 萬美元,因為 execute() 函式取決于 USDT-DKP 對中兩種代幣的余額比率。 智能合約黑客概述: 攻擊者的交易:0x0c850f,0x2d31 攻擊者地址:0xF38 利用合同:0xf34ad ......

    uj5u.com 2023-04-07 07:46:09 more
  • Defi開發簡介

    Defi開發簡介 介紹 Defi是去中心化金融的縮寫, 是一項旨在利用區塊鏈技術和智能合約創建更加開放,可訪問和透明的金融體系的運動. 這與傳統金融形成鮮明對比,傳統金融通常由少數大型銀行和金融機構控制 在Defi的世界里,用戶可以直接從他們的電腦或移動設備上訪問廣泛的金融服務,而不需要像銀行或者信 ......

    uj5u.com 2023-04-05 08:01:34 more
  • solidity簡單的ERC20代幣實作

    // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; import "hardhat/console.sol"; //ERC20 同質化代幣,每個代幣的本質或性質都是相同 //ETH 是原生代幣,它不是ERC20代幣, ......

    uj5u.com 2023-03-21 07:56:29 more
  • solidity 參考型別修飾符memory、calldata與storage 常量修飾符C

    在solidity語言中 參考型別修飾符(參考型別為存盤空間不固定的數值型別) memory、calldata與storage,它們只能修飾參考型別變數,比如字串、陣列、位元組等... memory 適用于方法傳參、返參或在方法體內使用,使用完就會清除掉,釋放記憶體 calldata 僅適用于方法傳參 ......

    uj5u.com 2023-03-08 07:57:54 more
  • solidity注解標簽

    在solidity語言中 注釋符為// 注解符為/* 內容*/ 或者 是 ///內容 注解中含有這幾個標簽給予我們使用 @title 一個應該描述合約/介面的標題 contract, library, interface @author 作者的名字 contract, library, interf ......

    uj5u.com 2023-03-08 07:57:49 more
  • 評價指標:相似度、GAS消耗

    【代碼注釋自動生成方法綜述】 這些評測指標主要來自機器翻譯和文本總結等研究領域,可以評估候選文本(即基于代碼注釋自動方法而生成)和參考文本(即基于手工方式而生成)的相似度. BLEU指標^[^?88^^?^]^:其全稱是bilingual evaluation understudy.該指標是最早用于 ......

    uj5u.com 2023-02-23 07:27:39 more
  • 基于NOSTR協議的“公有制”版本的Twitter,去中心化社交軟體Damus

    最近,一個幽靈,Web3的幽靈,在網路游蕩,它叫Damus,這玩意詮釋了什么叫做病毒式營銷,滑稽的是,一個Web3產品卻在Web2的產品鏈上瘋狂傳銷,各方大佬紛紛為其背書,到底發生了什么?Damus的葫蘆里,賣的是什么藥? 注冊和簡單實用 很少有什么產品在用戶注冊環節會有什么噱頭,但Damus確實出 ......

    uj5u.com 2023-02-05 06:48:39 more