資源の読み込みに... 荷物...

FMZ を使用してEthereumをベースにした web3 開発を簡単に開始する

作者: リン・ハーンFMZ~リディア, 作成日: 2023-06-25 09:17:53, 更新日: 2024-11-11 22:34:49

[TOC]

img

FMZ を使用してEthereumをベースにした web3 開発を簡単に開始する

EtherEaseWithFMZチュートリアル

簡単に FMZ を使ってEthereum ベースの web3 開発を開始します

イーサリアム (Ethereum) は,ブロックチェーン技術に基づいたスマートコントラクトプラットフォームで,スマートコントラクトを書くおよび展開する分散化された方法を提供します.スマートコントラクトは,ブロックチェーン上で自動的に実行し,第三者を信頼する必要なくさまざまなビジネスロジックを実装できる特別なタイプのコンピュータプログラムです.

FMZ量子取引プラットフォーム (FMZ.COM) は,開発者がイーサリアム・ブロックチェーンとそのエコシステムとより簡単に相互作用できるように,使いやすいAPIを提供します.分散型取引所 (DEX) にアクセスし,チェーン上のデータを取得し,トランザクションを送信し,その他の機能を達成します.

このチュートリアルでは,例はJavaScriptテスト環境は,両方を使用します.イーサリアム メインネットそしてゲルリ検査網FMZプラットフォームの API ドキュメンテーションで使用されているコード例もご覧いただけます.


FMZ の 開始

FMZ 量子取引プラットフォームの使い方を学ぶ前に,いくつかの基本的な概念を熟知する必要があります:

1. FMZ 量子取引プラットフォームアーキテクチャ

FMZ量子取引プラットフォームの公式ウェブサイトに登録してログインした後 (https://www.fmz.comFMZのウェブサイトは,システム全体の管理端であり,ユーザーによって書かれたプログラムは実際にdockerで実行されます.dockerソフトウェアプログラムは,サーバー,コンピュータなど,さまざまなデバイスに展開できます.ユーザーがプログラムを書いてFMZのウェブサイトで実行インスタンスを作成すると,FMZプラットフォームはdockerと通信し,その上でプログラムインスタンスを起動します.

2. ドッカー

プログラムインスタンスを実行したい場合は,dockerを展開する必要があります.dockerの展開も非常に簡単で,プラットフォームには展開チュートリアルがあります.また,FMZの代理でレンタルされたサーバーに自動的に展開するために,FMZが提供する"ワンクリック展開"を使用することもできます.

  • 個人デバイスにdockerを展開する

ネットワークが正常である限り (特定の交換インターフェース,ノードアドレスなど,対応するターゲットにアクセスできる必要があります) サーバー,パーソナルコンピュータ,その他のデバイスにdockerプログラムを展開および実行できます. 展開の主なステップは:

  1. ドッカープログラムが展開されるデバイスをログインするか,開きます.サーバーにログインするまたはコンピュータを起動してオペレーティングシステムに入力する.
  2. ドッカープログラムの対応バージョンをダウンロード (デバイスのオペレーティングシステムによって異なります) ダウンロードページ:https://www.fmz.com/m/add-node

img

  1. 圧縮されたパッケージです 圧縮を解除する必要があります
  2. 実行可能なファイルです. 実行可能なファイルです.robotFMZ にログインした後,あなたはあなたの自分のアドレスを参照することができますhttps://www.fmz.com/m/add-nodeページ (つまり,./robot -s node.fmz.com/xxxxxこのアドレスの文字列で,xxxxxFMZ アカウントの位置が異なる).最後に,あなたの FMZ アカウントのパスワードを入力する必要があります.これらの設定を設定した後,docker プログラムを実行します.
  • FMZプラットフォームの"ワンクリックデプロイメント"機能を使用

    FMZプラットフォームにドッカーページを追加する アドレス:https://www.fmz.com/m/add-node

    img

3. デバッグ ツール

FMZ Quant Trading Platformは,サポートする無料デバッグツールを提供します.JavaScript, TypeScriptページは次のとおりですhttps://www.fmz.com/m/debug. 実行するインスタンスの作成が請求されるため. 初期学習期間中,このデバッグツールをテストと学習のために使用できます. 最大実行時間制限3分を除いて,デバッグツールを使用して実行するインスタンスを作成する間に違いはありません.

薬剤を使用する場合TypeScript言語は,あなたが書く必要があります// @ts-check変更するコードの最初の行でTypeScript設定されている場合,デフォルトはJavaScript language.

4. プラットフォーム

FMZでは,Platformは一般的な概念である.CEX取引所では,特定の交換アカウント構成を指す.web3では,この交換は,ノードアドレスとプライベートキー構成を含む構成情報を指す.

FMZプラットフォームのログイン状態で,https://www.fmz.com/m/add-platform交換は一般的概念です. このページでは,情報交換を設定できます.

img

選択するWeb3セキュリティメカニズムを表示するには,右下角をクリックしてください.

ノードは,自作ノードまたはノードサービスプロバイダが提供するノードである.多くのノードサービスプロバイダがあります.インフュラ. 登録後,自分のアカウントのノードアドレスを表示できます. メインネットとテストネットの両方が利用可能で,かなり便利です. このノードアドレスを設定しますRpc Address設定された交換オブジェクトを区別するために,ラベルを自分で名付けることができます.

img

写真にはhttps://mainnet.infura.io/v3/xxxxxxxxxxxxxプライベートな Infura ETH メインネット RPC ノードアドレスです.


FMZ を使って Ethereum とやり取りする

交換オブジェクトを設定すると,FMZ.COMテストのためのDebugging Tool. Ethereum RPCメソッドを呼び出し,この章に記載され導入されたいくつかのRPCメソッドに加えて,Ethereum RPCメソッドと相互作用する.https://www.quicknode.com/docs.

Web3 にアクセスする方法は,様々な言語やツールで,図のように示されています.

img

FMZでは,RPCメソッド呼び出しもカプセル化され,これらの関数は FMZ API 関数にカプセル化されます.exchange.IO呼び出す方法はexchange.IO("api", "eth", ...). 最初のパラメータは"api", 2番目のパラメータは"eth",その他のパラメータは,呼び出される特定の RPC 方法に依存します.

輸出情報については,LogFMZプラットフォームの役割についてLog機能は複数のパラメータを受け入れ,それを FMZ プラットフォームの Debug Tool または Bot ページのログエリアに出力することができます. Debug Tool ページは私たちの主なテストツールになります.

eth_get バランス

についてeth_getBalanceこの方法は2つのパラメータを必要とします. この方法は,EthereumのEthereumアドレスのEthereumバランスをクエリするために使用されます.

  • アドレスを調べる
  • 標識では通常"最新"を使います Ethereumの創始者を調べてみましょうVitalik ButerinETHの財布の住所です 既知の住所は0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045.
function main() {
    let ethBalance = exchange.IO("api", "eth", "eth_getBalance", "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "latest")
    Log("ethBalance:", ethBalance)
}

すでにドッカー (写真: linux/amd64...) を展開し,交換オブジェクト (写真: Web3テスト) を構成し,デバッグツールでコードをテストしました:

img

実行ボタンをクリックしてコードを実行し,結果を表示します:

ethバランス: 0x117296558f185bbc4c6

についてlog機能が印刷するethBalance変数値として:0x117296558f185bbc4c6文字列の種類です.ETH バランスの十六進数値wei単位で1e18 wei1 に等しいETH読み取れる ETH のデシマル バランスになるように変換する必要があります

変換するethBalance読み取れるデータに:

function main() {
    let ethBalance = exchange.IO("api", "eth", "eth_getBalance", "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "latest")
    Log("ethBalance:", ethBalance)
    
    // Converting ethBalance into readable data
    let vitalikEthBalance = parseInt(ethBalance.substring(2), 16) / 1e18
    Log("vitalikEthBalance:", vitalikEthBalance)
}

検索を続けるhttps://etherscan.io/:

img

しかし,言語そのものの精度の問題により,この処理方法には偏差がある.したがって,FMZプラットフォームにはデータ処理のための2つの機能が組み込まれています:

  • BigInt: BigInt オブジェクトにヘクサデシマル文字列を変換する.
  • BigDecimal: 数値型オブジェクトを計算可能なBigDecimalオブジェクトに変換する.

コードを再調整する:

function main() {
    let ethBalance = exchange.IO("api", "eth", "eth_getBalance", "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "latest")

    // The precision unit of ETH is 1e18
    let ethDecimal = 18
    Log("vitalikEthBalance:", Number((BigDecimal(BigInt(ethBalance)) / BigDecimal(Math.pow(10, ethDecimal))).toString()))
}

ビタリックEth バランス: 5149.6244846875215

eth_chainId

eth_chainIdそしてnet_versionこの2つの機能は,現在のRPCノードが接続されているブロックチェーンIDを返します.net_versionデシマルの Id を返します.eth_chainIdhexadecimal id を返します.

ChainId に対応するネットワーク名

1 - ethereum mainnet
2 - morden testnet (deprecated)
3 - ropsten testnet
4 - rinkeby testnet
5 - goerli testnet
11155111 - sepolia testnet
10 - optimism mainnet
69 - optimism kovan testnet
42 - kovan testnet
137 - matic/polygon mainnet
80001 - matic/polygon mumbai testnet
250 - fantom mainnet
100 - xdai mainnet
56 - bsc mainnet

設定されたEthereumテストネットでテストするgoerliノード:

function main() {
    let netVersionId = exchange.IO("api", "eth", "net_version")
    let ethChainId = exchange.IO("api", "eth", "eth_chainId")

    Log("netVersionId:", netVersionId)
    Log("ethChainId:", ethChainId, " , conversion:", parseInt(ethChainId.substring(2), 16))
}

eth_gas 価格

呼んでeth_gasPriceコントローンのクエリ方法gas priceチェーンに

function toAmount(s, decimals) {
    return Number((BigDecimal(BigInt(s)) / BigDecimal(Math.pow(10, decimals))).toString())
}

function main() {
    let gasPrice = exchange.IO("api", "eth", "eth_gasPrice")
    Log("gasPrice:", gasPrice, " , conversion:", toAmount(gasPrice, 0))
}

読み取れる数値に変換する関数を書きます.toAmountさらに,単位はgasPricewei公式パラメータに対応する実数パラメータに 0 を渡します.decimals.

eth_block数

"eth_blockNumberブロックの高さを問い合わせるのに使われます

function toAmount(s, decimals) {
    return Number((BigDecimal(BigInt(s)) / BigDecimal(Math.pow(10, decimals))).toString())
}

function main() {
    let blockNumber = exchange.IO("api", "eth", "eth_blockNumber")
    Log(toAmount(blockNumber, 0))
}

デバッグツールを実行する:

img

検索を続けるhttps://etherscan.io/:

img

eth_getBlockByNumber ブロック番号

ブロック情報をクエリする

function main() {
    let blockNumber = exchange.IO("api", "eth", "eth_blockNumber")    
    Log(blockNumber)
    let blockMsg = exchange.IO("api", "eth", "eth_getBlockByNumber", blockNumber, true)
    Log(typeof(blockMsg), blockMsg)
    
    // Due to the excessive content of Log output, it will be truncated automatically, so traverse each field of the returned block information and print them one by one
    for (let key in blockMsg) {
        Log("key:", key, ", val:", blockMsg[key])
    }
}

デバッグツールで実行すると,次の情報を得ることができます:

img

契約情報を読む

Ethereumで実行されます.ENSそのうちの"人ですENSEthereum Name Service (イーサリアム・ネーム・サービス) は,イーサリアム・ブロックチェーンに基づいた分散ドメイン名解析サービスです. Ethereumの創設者Vitalik Buterinの財布の残高をチェックした例を覚えていますか? Vitalik Buterinの財布のアドレスの一つは:0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045アドレスをどうやって知るのか?ENSスマートコントラクトは直感的な名前を使用しますvitalik.eth.

この章の次のコンテンツは,Ethereum メインネット環境を使用しています.ENS文書Hashing Names以太坊のドメイン名への問い合わせに必要なものです.vitalik.eth.

function nameHash(name) {
    if (name == "") {
        return "0000000000000000000000000000000000000000000000000000000000000000"
    } else {
        let arr = name.split(".")
        let label = arr[0]
        
        arr.shift()
        let remainder = arr.join(".")
        return Encode("sha3.keccak256", "hex", "hex", nameHash(remainder) + Encode("sha3.keccak256", "raw", "hex", label))
    }
}

この関数には,別の未知の関数があります.Encode. この関数は FMZ プラットフォームの API 関数であり,FMZ プラットフォーム上の暗号化操作のために特に使用されます.この関数は複数の暗号化方法とさまざまなハッシュアルゴリズムをサポートします.

Encode(algo, inputFormat, outputFormat, data, keyFormat, key string)

ENS 文書の説明に従って,sha3.keccak256データを処理するアルゴリズムです

呼んでnameHash機能,例えば:Log(nameHash("vitalik.eth")),あなたは得ることができます:ee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a534758350xの前項を加える必要があります.0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835測定値のパラメータとして使用されます.resolverENSのスマートコントラクトで

let ensNode = "0x" + nameHash("vitalik.eth")    // Prepare the parameters ensNode for calling the resolver method

ENSのドキュメントによると,ENSのスマートコントラクトアプリケーションの契約アドレスは:0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e呼び出す前にresolverスマートコントラクトの方法,我々はまた,準備する必要がありますABI契約の内容です

ABI を登録する

このことを知ると,あなたは疑問に思うかもしれませんABIスマートコントラクト?

ABI, or Application Binary Interface, is the interface standard for smart contracts to communicate with the external world.
The ABI of a smart contract defines the contract's function interfaces, parameter types, return values, and other information, as well as specifications for calling the contract and passing parameters.

The ABI of a smart contract is usually stored in JSON format and contains the following information:

Contract function interfaces: function names, parameter lists, return values, etc.
Function parameter types: such as uint256, bool, string etc.
Encoding methods for input and output parameters of functions: Smart contracts use an encoding method called Solidity ABI to encode input and output parameters of functions so that they can interact with Ethereum network.
In Ethereum network ,the ABI of a smart contract is used to call its functions. When you need to call a contract function, you need to provide the name of the function, its parameters, and bytecode encoded according to ABI encoding method.
Ethereum nodes will package this information into transactions and send them out on Ethereum network for execution.

In Solidity language,the keyword 'interface' can be used define ABIs for smart contracts. Ethereum development tools like Remix IDE ,Truffle also provide editing & generation tools making it easier developers create & use ABIs.

抽出するresolverENSのABIから方法の一部,または完全なABIを使用することができます.https://etherscan.io/あるいは,他のチャネル (例えば,関連プロジェクト文書) でABIを取得する.

img

let abiENS_resolver = `[{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"resolver","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]`

FMZのプラットフォームで新しい呼び出し方法を学びますexchange.IO("abi", address, abiContent)ABI を登録するために使用されます.addressスマートコントラクトのアドレスとabiContentパラメータは対応するスマートコントラクト ABI (文字列) です.

let abiENS_resolver = `[{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"resolver","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]`
exchange.IO("abi", "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", abiENS_resolver)  // 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e is the address of the ENS smart contract deployed on the Ethereum mainnet

スマートコントラクトを呼び出す方法

次に,電話をかけてresolverENSのスマートコントラクトの方法で,ENS: Public Resolver contract.

img

let resolverAddress = exchange.IO("api", "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", "resolver", ensNode)

試しにENS: Public Resolver契約書addrビタリック・ブテリンの財布の住所を入手する方法ですENS: Public ResolverこのスマートコントラクトのABI情報は,https://etherscan.io/.

let abiENSPublicResolver = `[{"inputs":[{"internalType":"contract ENS","name":"_ens","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"contentType","type":"uint256"}],"name":"ABIChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"address","name":"a","type":"address"}],"name":"AddrChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"coinType","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"newAddress","type":"bytes"}],"name":"AddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"bool","name":"isAuthorised","type":"bool"}],"name":"AuthorisationChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"hash","type":"bytes"}],"name":"ContenthashChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"name","type":"bytes"},{"indexed":false,"internalType":"uint16","name":"resource","type":"uint16"},{"indexed":false,"internalType":"bytes","name":"record","type":"bytes"}],"name":"DNSRecordChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"name","type":"bytes"},{"indexed":false,"internalType":"uint16","name":"resource","type":"uint16"}],"name":"DNSRecordDeleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"DNSZoneCleared","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"bytes4","name":"interfaceID","type":"bytes4"},{"indexed":false,"internalType":"address","name":"implementer","type":"address"}],"name":"InterfaceChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"string","name":"name","type":"string"}],"name":"NameChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"x","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"y","type":"bytes32"}],"name":"PubkeyChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"string","name":"indexedKey","type":"string"},{"indexed":false,"internalType":"string","name":"key","type":"string"}],"name":"TextChanged","type":"event"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"contentTypes","type":"uint256"}],"name":"ABI","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"addr","outputs":[{"internalType":"address payable","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"coinType","type":"uint256"}],"name":"addr","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"authorisations","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"clearDNSZone","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"contenthash","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"name","type":"bytes32"},{"internalType":"uint16","name":"resource","type":"uint16"}],"name":"dnsRecord","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"name","type":"bytes32"}],"name":"hasDNSRecords","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"interfaceImplementer","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"pubkey","outputs":[{"internalType":"bytes32","name":"x","type":"bytes32"},{"internalType":"bytes32","name":"y","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"contentType","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"setABI","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"coinType","type":"uint256"},{"internalType":"bytes","name":"a","type":"bytes"}],"name":"setAddr","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"a","type":"address"}],"name":"setAddr","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bool","name":"isAuthorised","type":"bool"}],"name":"setAuthorisation","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes","name":"hash","type":"bytes"}],"name":"setContenthash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"setDNSRecords","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes4","name":"interfaceID","type":"bytes4"},{"internalType":"address","name":"implementer","type":"address"}],"name":"setInterface","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"string","name":"name","type":"string"}],"name":"setName","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"x","type":"bytes32"},{"internalType":"bytes32","name":"y","type":"bytes32"}],"name":"setPubkey","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"string","name":"key","type":"string"},{"internalType":"string","name":"value","type":"string"}],"name":"setText","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"string","name":"key","type":"string"}],"name":"text","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}]`
exchange.IO("abi", resolverAddress, abiENSPublicResolver)

img

最後に,電話をかけてENS: Public Resolver契約書addrパラメータがまだensNode.

let vitalikAddress = exchange.IO("api", resolverAddress, "addr", ensNode)
Log("vitalikAddress:", vitalikAddress)

ログ関数出力:

vitalikAddress: 0xd8da6bf26964af9d7eed9e03e53415d37aa96045

ENS の 完全な コード を 呼び出し

function nameHash(name) {
    if (name == "") {
        return "0000000000000000000000000000000000000000000000000000000000000000"
    } else {
        let arr = name.split(".")
        let label = arr[0]
        
        arr.shift()
        let remainder = arr.join(".")
        return Encode("sha3.keccak256", "hex", "hex", nameHash(remainder) + Encode("sha3.keccak256", "raw", "hex", label))
    }
}

function main() {
    // Calculate the name
    let ensNode = "0x" + nameHash("vitalik.eth")    

    // Register ENS contract
    let abiENS_resolver = `[{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"resolver","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]`
    exchange.IO("abi", "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", abiENS_resolver)
    let resolverAddress = exchange.IO("api", "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", "resolver", ensNode)
    
    // Register ENS Public Resolver contract
    let abiENSPublicResolver = `[{"inputs":[{"internalType":"contract ENS","name":"_ens","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"contentType","type":"uint256"}],"name":"ABIChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"address","name":"a","type":"address"}],"name":"AddrChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"coinType","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"newAddress","type":"bytes"}],"name":"AddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"bool","name":"isAuthorised","type":"bool"}],"name":"AuthorisationChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"hash","type":"bytes"}],"name":"ContenthashChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"name","type":"bytes"},{"indexed":false,"internalType":"uint16","name":"resource","type":"uint16"},{"indexed":false,"internalType":"bytes","name":"record","type":"bytes"}],"name":"DNSRecordChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"name","type":"bytes"},{"indexed":false,"internalType":"uint16","name":"resource","type":"uint16"}],"name":"DNSRecordDeleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"DNSZoneCleared","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"bytes4","name":"interfaceID","type":"bytes4"},{"indexed":false,"internalType":"address","name":"implementer","type":"address"}],"name":"InterfaceChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"string","name":"name","type":"string"}],"name":"NameChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"x","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"y","type":"bytes32"}],"name":"PubkeyChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"string","name":"indexedKey","type":"string"},{"indexed":false,"internalType":"string","name":"key","type":"string"}],"name":"TextChanged","type":"event"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"contentTypes","type":"uint256"}],"name":"ABI","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"addr","outputs":[{"internalType":"address payable","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"coinType","type":"uint256"}],"name":"addr","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"authorisations","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"clearDNSZone","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"contenthash","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"name","type":"bytes32"},{"internalType":"uint16","name":"resource","type":"uint16"}],"name":"dnsRecord","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"name","type":"bytes32"}],"name":"hasDNSRecords","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"interfaceImplementer","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"pubkey","outputs":[{"internalType":"bytes32","name":"x","type":"bytes32"},{"internalType":"bytes32","name":"y","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"contentType","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"setABI","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"coinType","type":"uint256"},{"internalType":"bytes","name":"a","type":"bytes"}],"name":"setAddr","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"a","type":"address"}],"name":"setAddr","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bool","name":"isAuthorised","type":"bool"}],"name":"setAuthorisation","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes","name":"hash","type":"bytes"}],"name":"setContenthash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"setDNSRecords","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes4","name":"interfaceID","type":"bytes4"},{"internalType":"address","name":"implementer","type":"address"}],"name":"setInterface","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"string","name":"name","type":"string"}],"name":"setName","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"x","type":"bytes32"},{"internalType":"bytes32","name":"y","type":"bytes32"}],"name":"setPubkey","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"string","name":"key","type":"string"},{"internalType":"string","name":"value","type":"string"}],"name":"setText","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"string","name":"key","type":"string"}],"name":"text","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}]`
    exchange.IO("abi", resolverAddress, abiENSPublicResolver)
    let vitalikAddress = exchange.IO("api", resolverAddress, "addr", ensNode)
    Log("vitalikAddress:", vitalikAddress)
}

ETH を送信する

設定された交換オブジェクトのこのプライベートキーに対応するウォレットアドレスをどのように知っていますか? FMZでは,exchange.IO("address")設定されたプライベートキーに対応するウォレットアドレスを取得する機能です

この章の次のコンテンツは Goerli テストネット環境を使用しているので,私が使用しているノードは:https://goerli.infura.io/v3/*******登録ユーザーごとに異なるノードアドレスを割り当てます.*******特定のコンテンツを隠します

function main() {
    let walletAddress = exchange.IO("address")
    Log("Testnet goerli wallet address:", walletAddress)
}

ウォレットアドレスを知ったら,Ethereumの RPC メソッドを使うことができます.eth_getTransactionCountEthereumでは,このカウントは非常に一般的です.nonceEthereumでは,nonceは,各トランザクションがユニークであることを確認するために使用されるユニークな数値です.これは増加する数値で,新しいトランザクションを送信するたびに自動的に増加します.したがって,スマートコントラクトにトランザクションを送信するときに,トランザクションがユニークで正しい順序であることを確認するために,nonceを提供する必要があります.この情報はいくつかの資料や文書で見つけることができます:

https://goethereumbook.org/en/

img

ほらPendingNonceAtGo言語のEthereumライブラリ内の関数は実際にeth_getTransactionCountRPC 方法について学びました.ここで,RPC 方法について学びました.exchange.IO("api", "eth", ...)また機能する

function toAmount(s, decimals) {
    return Number((BigDecimal(BigInt(s)) / BigDecimal(Math.pow(10, decimals))).toString())
}

function main() {
    let walletAddress = exchange.IO("address")
    Log("Testnet goerli wallet address:", walletAddress)

    /**
    * eth_getTransactionCount
    * @param address - string - The address from which the transaction count to be checked.
    * @param blockNumber - string - The block number as a string in hexadecimal format or tags.
    * @returns The integer of the number of transactions sent from an address encoded as hexadecimal.
    */
    let nonce: string = exchange.IO("api", "eth", "eth_getTransactionCount", walletAddress, "pending")
    Log("wallet address:", walletAddress, "current nonce:", nonce, ", convert to decimal:", toAmount(nonce, 0))
}

送金操作を説明する前に,いくつかの概念を簡単に理解しましょう. エサリアムで送金するとき,一定の量のETHトークンが消費されます (ガス料金として).ガス料金は2つのパラメータによって決定されます:

  • ガス価格

    しかし,イーサリアムネットワーク上のガス料金は,市場の需要とユーザーが支払うために用意している料金に応じて常に変動するので,コードに固定ガス料金を書くことは,時には理想的な選択ではありません.eth_gasPrice平均ガスの価格を得ることができます.

  • ガス制限

    標準的なエーテル転送は 21,000ユニットのガス制限があります

概念を理解した後にnonce, gasPriceそしてgasLimitFMZは非常にシンプルで使いやすい転送機能を提供します.

exchange.IO("api", "eth", "send", toAddress, toAmount)

移転に使用される場合,第3パラメータはexchange.IO送信として固定され,toAddressパラメータは,転送中に ETH を受信するアドレスであり,toAmountETHの移転額です.

パラメータnonce, gasPriceそしてgasLimitFMZで自動的に得られるシステムデフォルト値をすべて使用できます.

exchange.IO("api", "eth", "send", toAddress, toAmount, {gasPrice: 5000000000, gasLimit: 21000, nonce: 100})

テストネットワークの特定のアドレスに ETH を転送します

function toInnerAmount(s, decimals) {
    return (BigDecimal(s)*BigDecimal(Math.pow(10, decimals))).toFixed(0)
}

function main() {
    let walletAddress = exchange.IO("address")
    Log("Testnet goerli wallet address:", walletAddress)

    let ret = exchange.IO("api", "eth", "send", "0x4D75a08E870674E68cAE611f329A27f446A66813", toInnerAmount(0.01, 18))
    return ret // return Transaction Hash : 0xa6f9f51b00d8ae850b0f204380b59da98f4bbce34b813577d3d948f61de4734e
}

Ethereumの送金金額の単位はweiオーダーメイド機能toInnerAmount処理するために使用する必要があります.wei units.

クエリ トランザクション ハッシュ:0xa6f9f51b00d8ae850b0f204380b59da98f4bbce34b813577d3d948f61de4734eについてhttps://etherscan.io/.

img

また,クエリ転送ハッシュにコードを書くことができます.0xa6f9f51b00d8ae850b0f204380b59da98f4bbce34b813577d3d948f61de4734e, を使ってeth_getTransactionReceipt問い合わせの方法

function main() {
    let transHash = "0xa6f9f51b00d8ae850b0f204380b59da98f4bbce34b813577d3d948f61de4734e"
    let info = exchange.IO("api", "eth", "eth_getTransactionReceipt", transHash)
    return info
}

検索結果:

{
	"cumulativeGasUsed": "0x200850",
	"effectiveGasPrice": "0x1748774421",
	"transactionHash": "0xa6f9f51b00d8ae850b0f204380b59da98f4bbce34b813577d3d948f61de4734e",
	"type": "0x0",
	"blockHash": "0x6bdde8b0f0453ecd24eecf7c634d65306f05511e0e8f09f9ed3f59eee2d06ac7",
	"contractAddress": null,
	"blockNumber": "0x868a50",
	"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
	"gasUsed": "0x5208",
	"to": "0x4d75a08e870674e68cae611f329a27f446a66813",
	"status": "0x1",
	"transactionIndex": "0x23",
	"from": "0x6b3f11d807809b0b1e5e3243df04a280d9f94bf4",
	"logs": []
}

各欄に対応する記述:

blockHash - The hash value of the block where the transaction is located.
blockNumber - The block number of the block where the transaction is located, encoded in hexadecimal.
contractAddress - If it's a contract creation, the address of the contract; otherwise null.
cumulativeGasUsed - The total gas used when executing this transaction in the block.
effectiveGasPrice - Total base fee plus tip per unit of gas.
from - Sender's address.
gasUsed - Gas used by this specific transaction.
logs - Array of log objects generated by this transaction.
  address - Address that generated this log.
  topics - Data array with 0 to 4 indexed log parameters, each with 32 bytes. In Solidity, first topic is event signature hash (e.g., Deposit(address,bytes32,uint256)), unless you declare an event using anonymous specifier.
  data - Non-indexed parameters for logs with length of 32 bytes.
  blockNumber - The block number of the block where this log is located.
  transactionHash - Transaction hash at time when log was created. Null if pending state.
  transactionIndex - Index position during creation. Null if pending state.
  blockHash - The hash value for containing block.
  logIndex - Hexadecimal-encoded integer index position within containing block. Null if pending state.
  removed - True if deleted due to chain reorganization; false for valid logs.
logsBloom - Bloom filter for retrieving related logs.
status - Hexadecimal-encoded value either being '1' (success) or '0' (failure).
to - Receiving party's address; null for contract creation transactions.
transactionHash - The hash value associated with given transaction.
transactionIndex - Hexadecimal-encoded index position within its respective containing-block.
type - Type value.

Ethereum スマートコントラクトを呼んで

契約情報の読み取りに関する章では,Ethereumで展開されている ENS契約の方法を呼び出すための完全な例を使用しました.Readこの方法の呼び出しは,必要ありませんgasこの章では,我々はいくつかのガスについて話しました.WriteEthereumのスマートコントラクトの方法と,支払いの方法gasこの操作はネットワーク全体の各ノードとマイナーによって確認され ブロックチェーンの状態が変化します

ERC20

ERC20契約 (ERC20トークン契約) の場合,FMZプラットフォームは,ERC20契約のABIをシステムに直接組み込まれた共通のABIとしてリストし,ABIの登録のステップをなくします.

ABI をよりよく理解するには,それを使用する前に確認できます.

[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"},{"name":"wad","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"src","type":"address"},{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"wad","type":"uint256"}],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"tran

関連性

もっと