EOS-contract

github
office site

tyleraccount
Description EOS Token Sale Claim Key
Public key EOS5p6VPhWXp6UBojRsYbimjuwWsBLth6aFTsMrnuFoX2f2oM4LGZ
Private key 5HubX63BtvNRnRKUuXNLNR9FD34FxnudQuGdmev8kA3c26NCW4y

common usage

cleos -u http://192.168.1.85:8888 get table astyler12312 astyler12312

cleos -u http://192.168.1.85:8888 get account astyler12312

// 调用方法
cleos -u http://192.168.1.85:8888 push action shine post '{"from":"joe","to":"alice","memo":"Thanks to painting"}' -p

compile contract

1.2.x 旧版本方式

#使用 -o 生成wast文件和wasm文件
eosiocpp -o ./app.wast ./app.cpp
#使用 -g 生成abi文件
eosiocpp -g ./app.abi ./app.cpp

1.3.x 新版本方式

eosio-cpp -abigen ./xx.cpp
eosio-cpp -abigen -contract=Players ./Players.cpp

deploy contract

cleos -u https://api-kylin.eoslaomao.com set contract astyler12312 ./buyname

eos-contract-account git:(master) ✗ cleos -u https://api-kylin.eoslaomao.com set contract astyler12312 ./buyname
Reading WASM from ./buyname/buyname.wasm...
Publishing contract...
executed transaction: fc455a93ba1442597e457ff769bf2a5da878a24f6e10d682d4d2889f17d520c9 8680 bytes 2495 us
# eosio <= eosio::setcode {"account":"astyler12312","vmtype":0,"vmversion":0,"code":"0061736d01000000017d1460037f7e7f0060057f7...
# eosio <= eosio::setabi {"account":"astyler12312","abi":"0e656f73696f3a3a6162692f312e3000030d6275796e616d655f6167656e7400030...
warning: transaction executed locally, but may not be confirmed by the network yet ]
➜ eos-contract-account git:(master) ✗


// 1.2.x 旧版本方式
cleos set contract eosio ./ ./hello1.wast hello1.abi -p eosio@active

这行命令有五个参数:eosio表示部署合约的账户,./表示合约所在的文件夹,后面两个参数依次是.wast和.abi文件的路径,最后的-p eosio@active表示权限。

invoke action

push action

cleos -u http://192.168.1.85:8888 transfer astyler12312 buyname.vip "1.6000 EOS" "buytest-EOS76Cw3GN58rjmAUDXSH9qSsk9VpYYLnH7h68KpzcEkzPZifcRd1-seven.a"

cleos -u http://192.168.1.85:8888 transfer astyler12312 buyname.vip "1.6000 EOS" "buytest1-EOS76Cw3GN58rjmAUDXSH9qSsk9VpYYLnH7h68KpzcEkzPZifcRd1-eight.a"

cleos -u http://192.168.1.85:8888 transfer astyler12312 buyname.vip "1.6000 EOS" "buytest1-EOS76Cw3GN58rjmAUDXSH9qSsk9VpYYLnH7h68KpzcEkzPZifcRd1-eight.a-agentName"

cleos -u http://192.168.1.85:8888 transfer buyname buyname.vip "1.6000 EOS" "buytest-EOS76Cw3GN58rjmAUDXSH9qSsk9VpYYLnH7h68KpzcEkzPZifcRd1-seven.a"

cleos -u http://192.168.1.85:8888 transfer astyler12312 buyname.vip "1.0000 EOS" "buytes2-EOS76Cw3GN58rjmAUDXSH9qSsk9VpYYLnH7h68KpzcEkzPZifcRd1-seven.a"

memo 格式: 账户名-公钥-套餐名字-代理的名字
套餐名字:
seven.a - 表示名字长度为7
eight.a - 表示名字长度为8

私钥: 5JohqwPMtZkaEbF5rwAk427rQ1jJDPJJaQc4eNcWi8yVnwpNTsC
公钥: EOS76Cw3GN58rjmAUDXSH9qSsk9VpYYLnH7h68KpzcEkzPZifcRd1

cleos -u http://192.168.1.85:8888 transfer astyler12312 buyname.vip "1.6000 EOS" "buytest1-EOS76Cw3GN58rjmAUDXSH9qSsk9VpYYLnH7h68KpzcEkzPZifcRd1-eight.a-agentName"

查看表内容
cleos get table eosio eosio profile

通过上述指令查看表中的内容,参数eosio eosio profile分别表示前文提到过的code、scope和表名。

插入数据:
// 插入
cleos push action eosio create '["eosio","hammer","25","programmer"]' -p eosio@active
// 再次查询
cleos get table eosio eosio profile

// 切换账号插入数据
cleos push action eosio create '["testeosio","maggie","23","waitress"]' -p testeosio@active
// 查询
cleos get table eosio eosio profile

查询数据
cleos push action eosio get '["testeosio"]' -p testeosio@active
cleos push action eosio get '["testeosio"]' -p eosio@active

根据自定义索引age筛选数据
// 传入参数的第一个为年龄下限,第二个为年龄上限
cleos push action eosio agerange '["22","27"]' -p eosio@active

查询套餐

cleos -u http://192.168.1.85:8888 get table vip vip prices

common concept

eosiocpp是一个c++生成wasm和ABI文件的工具。

#使用 -o 生成wast文件和wasm文件
eosiocpp -o ./hello1.wast ./hello1.cpp
#使用 -g 生成abi文件
eosiocpp -g ./hello1.abi ./hello1.cpp

common concept

An EOSIO Smart Contract consists of a set of action and type definitions.
Action definitions specify and implement the behaviors of the contract.
The type definitions specify the required content and structures.

EOSIO actions operate primarily in a message-based communication architecture. A client invokes actions by sending (pushing) messages to nodeos.

EOSIO Smart Contracts can communicate with each other, e.g., to have another contract perform some operation pertinent to the completion of the current transaction, or to trigger a future transaction outside of the scope of the current transaction.

EOSIO supports two basic communication models, inline and deferred.

Communication among contracts should be considered as occurring asynchronously. The asynchronous communication model can result in spam, which the resource limiting algorithm will resolve.

There is no guarantee that a deferred action will be executed.

Action Name Restrictions

Action types are actually base32 encoded 64-bit integers.This means they are limited to the characters a-z, 1-5, and ‘.’ for the first 12 characters. If there is a 13th character then it is restricted to the first 16 characters (‘.’ and a-p).

Transaction Confirmations

By means of confirmation, you should see the transaction in the transaction history with the block number of which it is included.

From a global view of an EOSIO blockchain, every node in the EOSIO network gets a copy of and runs every action in every contract.
Some of the nodes are doing the actual work of the contract, while others are processing in order to prove the validity of the transaction blocks.

receiver is the account that is currently processing the action.
code is the account that authorized the contract.
action is the ID of the currently running action.

Transaction Limitations

Every transaction must execute in 30ms or less. If a transaction contains several actions, and the sum of these actions is greater than 30ms, the entire transaction will fail. In situations without concurrency requirements for their actions this can be circumvented by including the CPU consuming actions in separate transactions.

合约通信

EOSIO中的合约可以相互通信。它是通过基于消息的通信架构实现的。

EOS通信模型就是他们沟通的方式。通信模型有两种类型:Inline Communication Model(内联通信模型)和Deferred Communication Model(延时通信模型)。
6f0b34a3.png

内联操作(内联通信模型)

用户从智能合约A执行操作(Action #1)。当操作开始执行时,它会触发另外两个操作:来自智能合约B的操作Action #1.1和来自智能合约C的操作Action #1.2。一切都在当前交易中完成。
在当前交易中执行并与其完成相关的操作,称为inline action即内联操作。
重要的是要记住内联操作是作为调用操作的一部分执行的。因此,它们与原始交易的范围和权限相同。这是他们将被执行的保证。如果其中一个操作失败,则整个交易将失败。
b838a3ce.png

延时操作(延时通信模式)

6526bb28.png 根据生产者的判断,延时的操作最好可以安排在稍后的时间运行。无法保证延期操作将执行。 即使它们不属于同一交易,它们也具有发送它们的合约的权限。

交易可以包含N个操作。但是,每个交易必须在30ms或更短的时间内执行。如果交易包含多个操作,并且这些操作的总和大于30毫秒,则整个交易将失败。