Solidity

Solidity内联汇编简明指南

独自空忆成欢 提交于 2020-02-26 22:50:59
在用Solidity开发以太坊智能合约时,使用汇编可以直接与EVM交互,降低gas开销成本,更精细的控制智能合约的行为,因此值得Solidity开发者学习并加以利用。本文是Solidity汇编开发的简明教程,旨在帮助你快速熟悉如何在Solidity智能合约代码中嵌入汇编代码。 以太坊教程链接: Dapp入门 | 电商Dapp实战 | Token实战 | Php对接 | Java对接 | Python对接 | C#对接 | Dart对接 2、以太坊虚拟机和堆栈结构机器 以太坊虚拟机EVM有自己的指令集,该指令集中目前包含了144个操作码,详情参考 Geth源代码 这些指令是Solidity抽象出来的,可以在Solidity内联使用。例如: contract Assembler { function do_something_cpu() public { assembly { // start writing evm assembler language } } } EVM是一个栈虚拟机,栈这种数据结构只允许两个操作:压入(PUSH)或弹出(POP)数据。最后压入的数据位于栈顶,因此将被第一个弹出,这被称为后进先出(LIFO:Last In, First Out): 栈虚拟机将所有的操作数保存在栈上,关于栈虚拟机的详细信息可以参考 stack machine 基础 3

Android和Java以太坊开发区块链应用使用web3j类库

空扰寡人 提交于 2020-02-25 21:05:23
如何使用web3j为Java应用或Android App增加以太坊区块链支持,教程内容即涉及以太坊中的核心概念,例如账户管理包括账户的创建、钱包创建、交易转账,交易与状态、智能合约开发与交互、过滤器和事件等,同时也详细说明如何使用web3j提供的API开发接口与以太坊进行交互,是java工程师学习以太坊应用开发的不二选择。 以太坊概述 以太坊是备受关注的区块链,它基于密码学技术和P2P通信技术 构建了一个去中心化的平台,所有的交易同步保存在每个节点中, 通过将区块单向级联成链,以太坊有效的保证了交易的不可篡改: 智能合约平台 以太坊是第一个实现了虚拟机的区块链,因此为智能合约 - Smart Contract - 的运行提供了良好的支持环境。也正因为这个原因,以太坊被称为区块链 2.0,以区别于比特币代表的以数字加密货币为核心特征的区块链1.0。 可以将智能合约理解为机器之间的合同约定,在满足一定条件时自动 执行约定好的逻辑,例如在保险理赔流程中,如果理赔条件满足就自动 将赔偿金释放给出险人,这个流程就可以使用智能合约来实现。 有多种语言可以开发以太坊智能合约,但目前最常用的是类似于JavaScript的 Solidity语言。本课程中将采用Solidity讲解智能合约的开发。 JSON RPC与web3j 如果我们希望构造一个去中心化应用(DApp),除了智能合约的开发,

Questions about contract calling another contract

拈花ヽ惹草 提交于 2020-01-23 12:17:27
问题 Need help with two related Solidity questions. Question 1. Say, I have a contract calling another one: contract B { function f1() { ... } } contract A { B b; function f() { b.f1(); } } Will msg.sender for f1 be same as for f() ? Of will it be an address of a contract A ? Question 2. Say, I have contracts A and B. I want to have contract A { B b; A(address addr) { b = B(addr); } } In other language, I would use B b = null; in declaration, to avoid double initialization, but it does not work in

Questions about contract calling another contract

半腔热情 提交于 2020-01-23 12:17:08
问题 Need help with two related Solidity questions. Question 1. Say, I have a contract calling another one: contract B { function f1() { ... } } contract A { B b; function f() { b.f1(); } } Will msg.sender for f1 be same as for f() ? Of will it be an address of a contract A ? Question 2. Say, I have contracts A and B. I want to have contract A { B b; A(address addr) { b = B(addr); } } In other language, I would use B b = null; in declaration, to avoid double initialization, but it does not work in

Are there null like thing in solidity

家住魔仙堡 提交于 2020-01-12 04:23:12
问题 struct buyer{ uint amount; Status status; } mapping(address=>buyer) public buyers; mapping(uint=>address) buyerIndex; uint public buyerNum; //Order a product. function(){ uint doubleValue=value*2; uint amount=msg.value/doubleValue; if(buyers[msg.sender]==null){ //Error in this line buyer abuyer=buyer({amount:amount,status:Status.Created}); //Error in this line buyerNum++; buyerIndex[buyerNum]=msg.sender; buyers[msg.sender]=abuyer; }else{ buyers[msg.sender].amount+=amount; } Order(msg.sender

区块链100讲:以太坊存储类型(memory,storage)及变量存储详解

折月煮酒 提交于 2020-01-08 13:30:10
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1 数据存储位置(Data location)概念 1.1 storage, memory, calldata, stack区分 在 Solidity 中,有两个地方可以存储变量 : 存储(storage)以及内存(memory) 。Storage变量是指永久存储在区块链中的变量。Memory 变量则是临时的,当外部函数对某合约调用完成时,内存型变量即被移除。 内存(memory)位置还包含2种类型的存储数据位置,一种是calldata,一种是栈(stack)。 (1) calldata 这是一块只读的,且不会永久存储的位置,用来存储函数参数。 外部函数的参数(非返回参数)的数据位置被强制指定为 calldata ,效果跟 memory 差不多。 (2) 栈(stack) 另外,EVM是一个基于栈的语言,栈实际是在内存(memory)的一个数据结构,每个栈元素占为256位,栈最大长度为1024。 值类型的局部变量是存储在栈上。 不同存储的消耗(gas消耗)是不一样的,说明如下: storage 会永久保存合约状态变量,开销最大; memory 仅保存临时变量,函数调用之后释放,开销很小; stack 保存很小的局部变量,免费使用,但有数量限制(16个变量); calldata的数据包含消息体的数据

How to deploy truffle contract to dev network when using inheritance?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-05 07:36:09
问题 I have been attempting to deploy a contract using the Truffle framework, I have recently been testing these contracts on the development network. My contract was very large and when I attempted to deploy it to a test net, I was instructed to split it up so that the contract wouldn't exceed the gas limit. Although, bearing in mind this contract did deploy onto the development network with the default gas limit. So I took out parts of the contract and derived another contract from the base and

How to deploy truffle contract to dev network when using inheritance?

自闭症网瘾萝莉.ら 提交于 2020-01-05 07:35:35
问题 I have been attempting to deploy a contract using the Truffle framework, I have recently been testing these contracts on the development network. My contract was very large and when I attempted to deploy it to a test net, I was instructed to split it up so that the contract wouldn't exceed the gas limit. Although, bearing in mind this contract did deploy onto the development network with the default gas limit. So I took out parts of the contract and derived another contract from the base and

Solidity - Solidity code to Input JSON Description

我是研究僧i 提交于 2020-01-02 09:52:41
问题 I want to compile my ehtereum HelloWorld.sol smart contract. In all the tutorials is that you do it like this: var solc = require('solc'); var compiledContract = solc.compile(fs.readFileSync('HelloWorld.sol').toString(); where HelloWorld.sol is: pragma solidity ^0.5.1; contract HelloWorld { bytes32 message; constructor(bytes32 myMessage) public { message = myMessage; } function getMessage() public view returns(bytes32){ return message; } } In other words I put my raw Solidity contract code

如何在以太坊开发发行自己的ERC-20数字货币

谁说胖子不能爱 提交于 2019-12-27 13:38:10
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 今天我将向你展示如何在以太坊区块链上开发你自己的加密货币并将其出售!我将向你展示如何使用以太坊智能合约逐步创建自己的ERC-20代币和众筹销售,如何测试智能合约,如何将智能合约部署到以太坊区块链,以及如何构建ICO网站部署到网络上。我还将解释ERC-20代币是什么,以太坊代币如何工作,初始代币产品(ICO)如何工作。 什么是ERC-20代币? 以太坊区块链允许你创建自己的加密货币或代币,可以通过以太币(以太坊区块链的本地加密货币)购买。ERC-20只是一个标准,它指定了这些代币的行为方式,因此它们与加密货币交换等其他平台兼容。 那怎么做呢?让我们先来看看以太坊区块链的工作原理。 以太坊是像比特币一样的区块链。与比特币一样,以太坊也会跟踪拥有Ether的用户余额,以太坊的原生加密货币。与比特币不同,以太坊也是一个平台,允许你创建自己的代币而无需创建新的区块链。 你可以使用智能合约创建以太坊代币。ERC-20是一个标准,用于指定此代币智能合约应如何工作。 让我们用一个例子来理解ERC-20代币智能合约的工作原理。假设我们想要创建一个名为“My Token”的代币,其符号为“MTK”,并且存在100,000,000个这样的代币。 首先,代币智能合约跟踪一些基本代币属性。例如,它记录名称“My Token”