Transfer Gateway (LoomNetwork) @Rinkeby
はじめに
TransferGateway
前回 https://qiita.com/oggata/items/698cee81c60985cebc57
で、TransferGatewayのexampleを試してみました。
今回は、testnet(rinkeby)などを使って、複数の環境でtokenやcoinをTransferさせてみた覚書です。
TransferGatewayとは
普段使っているEthereumの世界(mainnetやtestnet)と、Loomnetworkの世界をつなぐための"玄関"となるのがTransferGatewayです。
馴染みのopenzeppelin-solidityなどから作ったERCのコントラクトに下記のような関数を付加し、これまでのEtereum環境と、Loomの環境それぞれにdeployすることで簡単に接続することが可能となります。
function depositToGateway(address _gateway, uint256 _uid) public {
safeTransferFrom(msg.sender, _gateway, _uid);
}
Network
(memo)
https://loomx.io/developers/docs/en/testnet-plasma.html
Name | Url | Type | Detail |
---|---|---|---|
loom_dapp_chain | 127.0.0.1:46658 | local | ローカルチェーンネットワーク |
extdev_plasma_us1 | extdev-plasma-us1.dappchains.com:80 | testnet | Loomテストネットのplasmaチェーン(安定的開発者β) |
Dev Plasma Test | test-z-asia1.dappchains.com | testnet | 実験的ベータ |
Validator Test | test-z-validator1.dappchains.com | testnet | バリデーターベータ |
Plasma Chain | plasma.dappchains.com | mainnet | エンドユーザーベータ (Loom MarketPlace) |
Mainnet | ユーザーベータ | ||
Social Chain | Block Explorer | メインネット | DelegateCall |
(memo)
(※Karmaをもらえる https://faucet.dappchains.com/ が動かなかったが、Karmaなしでもextdev_plasma_us1というネットワークを指定してdeploy可能。)
Name | Ethereum Link | TransferGateway Address |
---|---|---|
Devnet Plasma (extdev-plasma-us1) | Rinkeby | 0xb73C9506cb7f4139A4D6Ac81DF1e5b6756Fab7A2 |
Devnet Plasma (test-z-asia1) | Rinkeby | 0x3c826a09DF9ad39B9acF550b1bf35C9b6AfCd943 |
Plasma Chain | Mainnet | 0x223CA78df868367D214b444d561B9123c018963A |
Validator Test | Rinkeby | n/a |
(参考)https://loomx.io/developers/docs/ja/testnet-plasma.html
Setup
1.loomのインストール
$ curl https://raw.githubusercontent.com/loomnetwork/loom-sdk-documentation/master/scripts/get_loom.sh | sh
$ ./loom
$ ./loom init
$ ./loom run
$ history
$ ./loom genkey -k priv_key -a pub_key
local address: 0xF6337F78a0AF189d5ee9Ba4314364f8658B4A745
local address base64: 9jN/eKCvGJ1e6bpDFDZPhli0p0U=
2.explorerを開く
https://blockexplorer.loomx.io/
を開き、下記のloomが起動しているローカルのaddress+IPを入力する
http://127.0.0.1:46658
3.sampleのインストール
$ git clone https://github.com/loomnetwork/truffle-dappchain-example
$ cd truffle-dappchain-example/
$ cp ../priv_key extdev_private_key
$ npm install -g yarn
$ yarn
//yarn deployはデフォルトで、loom_dapp_chainにdeployする.
//package.jsonに "deploy:extdev": "truffle deploy --network extdev_plasma_us1",
//と記載されているのでこの場合は、extdev_plasma_us1にdeployする
$ yarn deploy
Starting migrations...
======================
> Network name: 'loom_dapp_chain'
> Network id: 13654820909954
> Block gas limit: 0
$ yarn deploy:extdev
Starting migrations...
======================
> Network name: 'extdev_plasma_us1'
> Network id: 9545242630824
> Block gas limit: 0
$ curl https://raw.githubusercontent.com/loomnetwork/loom-sdk-documentation/master/scripts/get_loom.sh | sh
$ ./loom
$ ./loom init
$ ./loom run
$ history
$ ./loom genkey -k priv_key -a pub_key
local address: 0xF6337F78a0AF189d5ee9Ba4314364f8658B4A745
local address base64: 9jN/eKCvGJ1e6bpDFDZPhli0p0U=
https://blockexplorer.loomx.io/
を開き、下記のloomが起動しているローカルのaddress+IPを入力する
http://127.0.0.1:46658
$ git clone https://github.com/loomnetwork/truffle-dappchain-example
$ cd truffle-dappchain-example/
$ cp ../priv_key extdev_private_key
$ npm install -g yarn
$ yarn
//yarn deployはデフォルトで、loom_dapp_chainにdeployする.
//package.jsonに "deploy:extdev": "truffle deploy --network extdev_plasma_us1",
//と記載されているのでこの場合は、extdev_plasma_us1にdeployする
$ yarn deploy
Starting migrations...
======================
> Network name: 'loom_dapp_chain'
> Network id: 13654820909954
> Block gas limit: 0
$ yarn deploy:extdev
Starting migrations...
======================
> Network name: 'extdev_plasma_us1'
> Network id: 9545242630824
> Block gas limit: 0
この2つの環境についてtruffle-configに記述されている。
loom_dapp_chain: {
provider: function() {
const privateKey = readFileSync(path.join(__dirname, 'private_key'), 'utf-8')
const chainId = 'default'
const writeUrl = 'http://127.0.0.1:46658/rpc'
const readUrl = 'http://127.0.0.1:46658/query'
const loomTruffleProvider = new LoomTruffleProvider(chainId, writeUrl, readUrl, privateKey)
loomTruffleProvider.createExtraAccountsFromMnemonic("gravity top burden flip student usage spell purchase hundred improve check genre", 10)
return loomTruffleProvider
},
network_id: '*'
},
extdev_plasma_us1: {
provider: function() {
const privateKey = readFileSync(path.join(__dirname, 'extdev_private_key'), 'utf-8')
const chainId = 'extdev-plasma-us1'
const writeUrl = 'http://extdev-plasma-us1.dappchains.com:80/rpc'
const readUrl = 'http://extdev-plasma-us1.dappchains.com:80/query'
return new LoomTruffleProvider(chainId, writeUrl, readUrl, privateKey)
},
network_id: '9545242630824'
},
$ yarn gen:rinkeby-key
#Rinkeby
https://faucet.rinkeby.io/
$ export INFURA_API_KEY=1234567890
$ yarn deploy:rinkeby
ExtDevコインとRinkebyトークンの交換
アドレスを紐付ける
node ./gateway-cli.js map-contracts token
//(MyTokenContractAddress)->(MyRinkebyTokenContractAddress)
Submitted request to map 0x2A7B63620AEd6DF6cE3447e20E58cAcCFD6538D3 to 0xE2759F793AFf841B49Dc97a26819109491F0403D
node ./gateway-cli.js map-contracts coin
//(MyCoinContractAddress)->(MyRinkebyCoinContractAddress)
Submitted request to map 0xD41fB46DFD4a4e5f73Ac6F18339ec87465Cb86aA to 0x3A37F91077c0BEb27089e7B7E8383CF7E25405B8
//rinkebyのコントラクトaddress <-> rinkebery-Address From
//(MyRinkebyToken address(wallet address))<->(LoomLocalAddress)
mapping eth:0x2210d424a2cf814fc9d78dd094b52a7a0edbed14 to extdev-plasma-us1:0xf6337f78a0af189d5ee9ba4314364f8658b4a745
Mapped extdev-plasma-us1:0xf6337f78a0af189d5ee9ba4314364f8658b4a745 to eth:0x2210d424a2cf814fc9d78dd094b52a7a0edbed14
tokenをmint
//idを指定してRinkebyでtokenをmintする
$ node ./gateway-cli.js mint-token 1
Token 1 minted, Rinkeby tx hash: 0x1421e67f0be56fb37196258b52c7c83401765ae65db651d78bdaa9d57bfe9863
$ node ./gateway-cli.js mint-token 2
Token 2 minted, Rinkeby tx hash: 0xcf11f7ab25d3ff71aa962d119a0b3f8a8e499e878caac44fa8a8ff907a94bcbe
$ node ./gateway-cli.js mint-token 3
Token 3 minted, Rinkeby tx hash: 0x85740398d62c9c2a95e1a6fc91abbb5be999f6a60645d799c19e1b8719dd691a
tokenの転送例
//token1をrinkeby->ext-devに転送する
$ node ./gateway-cli.js deposit-token 1
Token 1 deposited, Rinkeby tx hash: 0x475079d79de98bc9baa642eb41321a50ef7f0f1955844af891fc3ded91e38df8
//Rinkebyのtoken残高
$ node ./gateway-cli.js token-balance -c eth
0x2210d424A2cf814fC9d78DD094b52a7A0EDbEd14 owns 2 tokens.
First 2 token(s): 3,2
//ext-devのtoken残高
$ node ./gateway-cli.js token-balance
0xf6337f78a0af189d5ee9ba4314364f8658b4a745 owns 1 tokens.
Gateway(Rinkeby)の保有残高
node ./gateway-cli.js token-balance -a gateway -c eth
0xb73C9506cb7f4139A4D6Ac81DF1e5b6756Fab7A2 owns 1 tokens.
coinの転送例
$ node ./gateway-cli.js deposit-coin 120
120 tokens deposited to Ethereum Gateway.
Rinkeby tx hash: 0x34fc4f092cfe7bd9846d7c5119455b1752b5e121d0d81d1ff0683abd228d7a8b
// Rinkebyの残高
$ node ./gateway-cli.js coin-balance -c eth
0x2210d424A2cf814fC9d78DD094b52a7A0EDbEd14 balance is 999999880
// extdevの残高
$ node ./gateway-cli.js coin-balance
0xf6337f78a0af189d5ee9ba4314364f8658b4a745 balance is 0
// Gateway(Rinkeby)の残高
$ node ./gateway-cli.js coin-balance -a gateway -c eth
0xb73C9506cb7f4139A4D6Ac81DF1e5b6756Fab7A2 balance is 120
ext-devからRinkebyにtokenを戻す
# Rinkebyに戻す
node ./gateway-cli.js withdraw-token 1
# Rinkeby残高
node ./gateway-cli.js token-balance -c eth
# extdev残高
node ./gateway-cli.js token-balance
ext-devからRinkebyにcoinを戻す
node ./gateway-cli.js token-balance -a gateway -c eth
# Rinkebyに60戻す
node ./gateway-cli.js withdraw-coin 60
# Rinkeby残高
node ./gateway-cli.js coin-balance -c eth
# extdev残高
node ./gateway-cli.js coin-balance
# Gateway(Rinkeby)残高
node ./gateway-cli.js coin-balance -a gateway -c eth
参考
node ./gateway-cli.js map-contracts token
//(MyTokenContractAddress)->(MyRinkebyTokenContractAddress)
Submitted request to map 0x2A7B63620AEd6DF6cE3447e20E58cAcCFD6538D3 to 0xE2759F793AFf841B49Dc97a26819109491F0403D
node ./gateway-cli.js map-contracts coin
//(MyCoinContractAddress)->(MyRinkebyCoinContractAddress)
Submitted request to map 0xD41fB46DFD4a4e5f73Ac6F18339ec87465Cb86aA to 0x3A37F91077c0BEb27089e7B7E8383CF7E25405B8
//rinkebyのコントラクトaddress <-> rinkebery-Address From
//(MyRinkebyToken address(wallet address))<->(LoomLocalAddress)
mapping eth:0x2210d424a2cf814fc9d78dd094b52a7a0edbed14 to extdev-plasma-us1:0xf6337f78a0af189d5ee9ba4314364f8658b4a745
Mapped extdev-plasma-us1:0xf6337f78a0af189d5ee9ba4314364f8658b4a745 to eth:0x2210d424a2cf814fc9d78dd094b52a7a0edbed14
//idを指定してRinkebyでtokenをmintする
$ node ./gateway-cli.js mint-token 1
Token 1 minted, Rinkeby tx hash: 0x1421e67f0be56fb37196258b52c7c83401765ae65db651d78bdaa9d57bfe9863
$ node ./gateway-cli.js mint-token 2
Token 2 minted, Rinkeby tx hash: 0xcf11f7ab25d3ff71aa962d119a0b3f8a8e499e878caac44fa8a8ff907a94bcbe
$ node ./gateway-cli.js mint-token 3
Token 3 minted, Rinkeby tx hash: 0x85740398d62c9c2a95e1a6fc91abbb5be999f6a60645d799c19e1b8719dd691a
//token1をrinkeby->ext-devに転送する
$ node ./gateway-cli.js deposit-token 1
Token 1 deposited, Rinkeby tx hash: 0x475079d79de98bc9baa642eb41321a50ef7f0f1955844af891fc3ded91e38df8
//Rinkebyのtoken残高
$ node ./gateway-cli.js token-balance -c eth
0x2210d424A2cf814fC9d78DD094b52a7A0EDbEd14 owns 2 tokens.
First 2 token(s): 3,2
//ext-devのtoken残高
$ node ./gateway-cli.js token-balance
0xf6337f78a0af189d5ee9ba4314364f8658b4a745 owns 1 tokens.
Gateway(Rinkeby)の保有残高
node ./gateway-cli.js token-balance -a gateway -c eth
0xb73C9506cb7f4139A4D6Ac81DF1e5b6756Fab7A2 owns 1 tokens.
$ node ./gateway-cli.js deposit-coin 120
120 tokens deposited to Ethereum Gateway.
Rinkeby tx hash: 0x34fc4f092cfe7bd9846d7c5119455b1752b5e121d0d81d1ff0683abd228d7a8b
// Rinkebyの残高
$ node ./gateway-cli.js coin-balance -c eth
0x2210d424A2cf814fC9d78DD094b52a7A0EDbEd14 balance is 999999880
// extdevの残高
$ node ./gateway-cli.js coin-balance
0xf6337f78a0af189d5ee9ba4314364f8658b4a745 balance is 0
// Gateway(Rinkeby)の残高
$ node ./gateway-cli.js coin-balance -a gateway -c eth
0xb73C9506cb7f4139A4D6Ac81DF1e5b6756Fab7A2 balance is 120
# Rinkebyに戻す
node ./gateway-cli.js withdraw-token 1
# Rinkeby残高
node ./gateway-cli.js token-balance -c eth
# extdev残高
node ./gateway-cli.js token-balance
node ./gateway-cli.js token-balance -a gateway -c eth
# Rinkebyに60戻す
node ./gateway-cli.js withdraw-coin 60
# Rinkeby残高
node ./gateway-cli.js coin-balance -c eth
# extdev残高
node ./gateway-cli.js coin-balance
# Gateway(Rinkeby)残高
node ./gateway-cli.js coin-balance -a gateway -c eth
(一連のtestnetでの流れ)
https://loomx.io/developers/docs/en/extdev-transfer-gateway.html
Author And Source
この問題について(Transfer Gateway (LoomNetwork) @Rinkeby), 我々は、より多くの情報をここで見つけました https://qiita.com/oggata/items/9e95a160de01f2fa865c著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .