Asset Exchange: Besu with Besu
We divide this page into two sections, if you used default configuration in ledger initialization step, then go to section AliceERC721 with BobERC20, otherwise if you used hybrid tokens in network, then go to section AliceERC1155 with BobERC20
| Notes |
|---|
The hash used in following steps can be replaced by any valid SHA256 hash. |
AliceERC721 with BobERC20
One Besu network transfers an non-fungible AliceERC721 token with id 0 from Alice to Bob in exchange for a transfer of 10 BobERC20 tokens from Bob to Alice in the other network. We will use account 1 for Alice and account 2 for Bob in both networks.
Run the following steps:
- Navigate to the
samples/besu/besu-clifolder in your clone of the Weaver repository. - Run the following to verify the status of the assets owned by
aliceandbobin the two networks:./bin/besu-cli asset get-balance --network=network1 --account=1
./bin/besu-cli asset get-balance --network=network1 --account=2
./bin/besu-cli asset get-balance --network=network2 --account=1
./bin/besu-cli asset get-balance --network=network2 --account=2 - Generate Secret-Hash Pair using following command (prints hash in base64):
./bin/besu-cli hash --hash_fn=SHA256 secrettext - Run the following to trigger
alicelockingAliceERC721token with id0forbobinnetwork1for 1 hourValue set to./bin/besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --token_id=0 --asset_type=ERC721 --timeout=3600 --hash_base64=ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs=hash_base64argument corresponds to what was generated in Step 3. Note thecontract-idprinted as output in above command. The output line containingcontract-id(text in base64 afterLock contract ID:) would like this:Lock contract ID: 48f59da2ac632117bf79b4aa986f5ece8a2439dc143d576965c17bc8275b0925 - Run the following to verify
alice's lock, replacing<contract-id>with actualcontract-id:./bin/besu-cli asset is-locked --network=network1 --lock_contract_id=<contract-id> - Run the following to trigger
boblocking10units ofBobERC20tokens foraliceinnetwork2for 30 mins:Note the./bin/besu-cli asset lock --network=network2 --sender_account=2 --recipient_account=1 --amount=10 --timeout=1800 --hash_base64=ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs=contract-idagain for this lock printed as output in above command. Let's refer it<contract-id-2>for this demonstration. - Run the following to verify
bob's lock:./bin/besu-cli asset is-locked --network=network2 --lock_contract_id=<contract-id-2> - Run the following to trigger
alice's claim for10units ofBobERC20tokens locked bybobinnetwork2:./bin/besu-cli asset claim --network=network2 --recipient_account=1 --preimage=secrettext --lock_contract_id=<contract-id-2> - Run the following to trigger
bob's claim forAliceERC721NFT with id0locked byaliceinnetwork1:./bin/besu-cli asset claim --network=network1 --recipient_account=2 --preimage=secrettext --token_id=0 --lock_contract_id=<contract-id>
The above steps complete a successful asset exchange between two Besu networks. In addition to the above commands, following commands can be run if specified timeout has expired and the locked asset remains unclaimed.
- If
alicewants to unlock the asset, run the following to triggeralice's re-claim forAliceERC721NFT with id0locked innetwork1:./bin/besu-cli asset unlock --network=network1 --lock_contract_id=<contract-id> --sender_account=1 --token_id=0 - If
bobwants to unlock the token asset, run the following to triggerbob's re-claim for10 BobERC20tokens locked innetwork2:./bin/besu-cli asset unlock --network=network2 --lock_contract_id=<contract-id-2> --sender_account=2
AliceERC1155 with BobERC20
One Besu network transfers an non-fungible 5 AliceERC1155 tokens with id 0 from Alice to Bob in exchange for a transfer of 50 BobERC20 tokens from Bob to Alice in the other network. We will use account 1 for Alice and account 2 for Bob in both networks.
Run the following steps:
- Navigate to the
samples/besu/besu-clifolder in your clone of the Weaver repository. - Run the following to verify the status of the assets owned by
aliceandbobin the two networks:./bin/besu-cli asset get-balance --network=network1 --account=1
./bin/besu-cli asset get-balance --network=network1 --account=2
./bin/besu-cli asset get-balance --network=network2 --account=1
./bin/besu-cli asset get-balance --network=network2 --account=2 - Generate Secret-Hash Pair using following command (prints hash in base64):
./bin/besu-cli hash --hash_fn=SHA256 secrettext - Run the following to trigger
alicelocking5 AliceERC1155token with id0forbobinnetwork1for 1 hourValue set to./bin/besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --amount=5 --token_id=0 --asset_type=ERC1155 --timeout=3600 --hash_base64=ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs=hash_base64argument corresponds to what was generated in Step 3. Note thecontract-idprinted as output in above command. The output line containingcontract-id(text in base64 afterLock contract ID:) would like this:Lock contract ID: 48f59da2ac632117bf79b4aa986f5ece8a2439dc143d576965c17bc8275b0925 - Run the following to verify
alice's lock, replacing<contract-id>with actualcontract-id:./bin/besu-cli asset is-locked --network=network1 --lock_contract_id=<contract-id> - Run the following to trigger
boblocking50units ofBobERC20tokens foraliceinnetwork2:Note the./bin/besu-cli asset lock --network=network2 --sender_account=2 --recipient_account=1 --amount=50 --timeout=3600 --hash_base64=ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs=contract-idagain for this lock printed as output in above command. Let's refer it<contract-id-2>for this demonstration. - Run the following to verify
bob's lock:./bin/besu-cli asset is-locked --network=network2 --lock_contract_id=<contract-id-2> - Run the following to trigger
alice's claim for50units ofBobERC20tokens locked bybobinnetwork2:./bin/besu-cli asset claim --network=network2 --recipient_account=1 --preimage=secrettext --lock_contract_id=<contract-id-2> - Run the following to trigger
bob's claim for5 AliceERC1155tokens with id0locked byaliceinnetwork1:./bin/besu-cli asset claim --network=network1 --recipient_account=2 --preimage=secrettext --token_id=0 --lock_contract_id=<contract-id>
The above steps complete a successful asset exchange between two Besu networks. In addition to the above commands, following commands can be run if specified timeout has expired and the locked asset remains unclaimed.
- If
alicewants to unlock the asset, run the following to triggeralice's re-claim for5 AliceERC1155tokens with id0locked innetwork1:./bin/besu-cli asset unlock --network=network1 --lock_contract_id=<contract-id> --sender_account=1 --token_id=0 - If
bobwants to unlock the token asset, run the following to triggerbob's re-claim for50 BobERC20tokens locked innetwork2:./bin/besu-cli asset unlock --network=network2 --lock_contract_id=<contract-id-2> --sender_account=2
Run the following to verify the status of the assets owned by alice and bob in the two networks:
./bin/besu-cli asset get-balance --network=network1 --account=1
./bin/besu-cli asset get-balance --network=network1 --account=2
./bin/besu-cli asset get-balance --network=network2 --account=1
./bin/besu-cli asset get-balance --network=network2 --account=2