typscript: line edits

This commit is contained in:
Eric Wong 2022-09-23 13:14:40 -05:00
parent ddf4d7924e
commit 496b5c33bf
4 changed files with 25 additions and 17 deletions

View File

@ -1,10 +1,12 @@
# Registering Tokens
Registering tokens with the token bridge can be done from any supported blockchain, and only needs to be done once - globally - per token. This is is typically done via a UI (such as the [Portal UI](portalbridge.com)) rather than done on-chain.
Registering tokens with the token bridge can be done from any supported blockchain, and only needs to be done once - globally - per token. This is is typically done via a UI (such as [Portal](portalbridge.com)) rather than done on-chain.
If you need to do it programmatically, you can also use the Typescript SDK to attest a token:
If you need to do it programmatically, you can also use the Typescript SDK to attest a token.
The first step is to create an AttestMeta VAA. We do this by calling `attest()` function from the SDK and passing in the Token Bridge address, and the address of the Token we want to attest.
There are three steps to registerring a token:
1. Create an AttestMeta VAA by calling `attest()` function from the SDK and passing in the Token Bridge address, and the address of the Token we want to attest.
For example, here is the code to produce an attestation VAA using ethers:
@ -18,7 +20,7 @@ const networkTokenAttestation = await attestFromEth(
The attestation transaction will produce a signed VAA. This signed VAA is necessary in order to register the tokens on other chains.
In order to retrieve the VAA, you will need the `emitterAddress` of the Token Bridge and the `sequence` from the logs of the transaction receipt.
2. Retrieve the VAA with the `emitterAddress` of the Token Bridge and the `sequence` from the logs of the transaction receipt.
With those, you can fetch the VAA from any Guardian REST endpoint. It could take a moment (up to 30 seconds) for the Guardian to see and sign the VAA, so it's a good idea to poll the Guardian every few seconds until the VAA is found.
@ -40,7 +42,7 @@ while (!vaaBytes.vaaBytes) {
}
```
Lastly, we submit the VAA onto the target chain to create a wrapped version of the token. This is accomplished by calling `createWrapped()`.
3. Submit the VAA onto the target chain to create a wrapped version of the token by calling `createWrapped()`.
You can get the new wrapped token address by calling the `wrappedAsset()` function of the TokenBridge.

View File

@ -1,6 +1,6 @@
# Wormhole Typescript SDK
For applications that only need to interact with the Core and Token Bridge contracts off-chain, there is a Wormhole Typescript SDK provided.
A Wormhole Typescript SDK provided for applications that only need to interact with the Core and Token Bridge contracts off-chain.
It can be installed using npm:
@ -8,6 +8,8 @@ It can be installed using npm:
npm i @certusone/wormholesdk
```
An explanation of the key concepts of using the Typescript SDK will be outlined in the following section, as well as some examples. For more examples with a more exhaustive coverage of all the supported blockchains in Wormhole, be sure to check the [official codebase](https://github.com/wormhole-foundation/wormhole/tree/dev.v2/sdk/js) for the Typescript SDK.
The following sections will explain and provide examples of how to perform key functions with Wormhole using the Typescript SDK.
For more examples with a more exhaustive coverage of all the supported blockchains in Wormhole, be sure to check the [official codebase](https://github.com/wormhole-foundation/wormhole/tree/dev.v2/sdk/js) for the Typescript SDK.
Virtually all functions of the SDK are demonstrated in the [reference bridge UI](https://github.com/wormhole-foundation/example-token-bridge-ui), which makes it an excellent source of example code as well.

View File

@ -2,9 +2,11 @@
<!-- //TODO this information should be captured elsewhere One challenge that arises for new EVM developers is that, because EVM uses unsigned integers, there's no concept of decimals. Therefore, tokens usually have up to 18 zeros behind them to denote up to 18 decimal places. Wormhole normalizes this to *eight* zeros, with transfer amounts rounded down to the nearest 8th decimal. -->
Before transferring tokens, you should ensure that the token is [Registered](./attestingToken.md) on the chain you are transferring to, and that any necessary prerequisite steps (such as sending token approvals or creating associated token accounts) have already been done.
Before transferring tokens, you should ensure that the token is [registered](./attestingToken.md) on the chain you are transferring to, and that any necessary prerequisite steps (such as sending token approvals or creating associated token accounts) have already been done.
For example, you'll likely need to do a standard ERC-20 token approval prior to performing a bridge action if you're in the EVM ecosystem.
There are four steps to transferring a token:
1. If not already done, complete a standard ERC-20 token approval prior to performing a bridge action if you're in the EVM ecosystem.
```js
// Here we are approving and transfering 50 tokens. The ERC20 token we are transfering has 18 decimal places.
@ -15,7 +17,9 @@ await treasury.approveTokenBridge(bridgeAmt, {
});
```
Once any prerequisite steps have been handled, simply call `transfer` on the token bridge module to initiate a transfer and create a transfer VAA. Note that the target receipient is a Wormhole-format address (referred to as 'hex' format in the Typescript SDK).
2. Initate a transfer by calling `transfer` on the token bridge module which will create a transfer VAA.
_Note that the target receipient is a Wormhole-format address (referred to as 'hex' format in the Typescript SDK)._
```js
const targetRecepient = Buffer.from(
@ -32,9 +36,7 @@ const tx = await (
).wait();
```
If you're not using a relayer, you'll have to submit the target chain transaction yourself. [This section](./polygon-oasis-relayer.md) outlines how to use relayers.
This code shows how to retrieve the VAA. (It's the same code as shown in the previous section.)
3. Retrieve the VAA with the `emitterAddress` of the Token Bridge and the `sequence` from the logs of the transaction receipt. (This is the same code as shown in the previous section.)
```js
const emitterAddr = getEmitterAddressEth(network.tokenBridgeAddress);
@ -48,7 +50,9 @@ while (!vaaBytes.vaaBytes) {
}
```
After we've fetched the VAA, we can call the `completeTransfer()` function on the target chain.
4. Submit the VAA to the target chain by calling `completeTransfer()`.
If you're not using a relayer, you'll have to submit the target chain transaction yourself. [This section](./polygon-oasis-relayer.md) outlines how to use relayers.
```js
const completeTransferTx = await targetTokenBridge.completeTransfer(

View File

@ -1,6 +1,6 @@
# Using Relayers
In this example, well utilize the token bridge relayer network to complete a token transfer. We'll start on Polygon and send tokens to Oasis.
In this example, well utilize the token bridge relayer network to complete a token transfer from Polygon and to Oasis.
This code is written for a browser environment. If you're working in node, consider using node-fetch:
@ -43,7 +43,7 @@ const PolygonWallet = new ethers.Wallet(
Fetch the fee schedule for the token bridge relayers. This fee schedule outlines the minimum fee for each recipient chain that relayers will accept. As long as we attach at least that fee in the relayer fee, we can expect a relayer pick up the transaction and relay it to the recipient chain. The fee will cover the gas cost for the relayer along with a little extra to make it worth their time to run the relayer service.
We will also define the transfer amount in this step. The fee schedule will either return a flat fee in USD for the recipient chain, or a percentage fee (usually only for Ethereum). Either way, well need to calculate the fee in in BigNumber format (no decimals).
We will also define the transfer amount in this step. The fee schedule will either return a flat fee in USD for the recipient chain, or a percentage fee (usually only for Ethereum). Either way, well need to calculate the fee in BigNumber format (no decimals).
```ts
const transferAmount = BigNumber.from("1000000000000000000"); // We are sending 1 MATIC over the wall to Oasis
@ -147,7 +147,7 @@ console.log("EmitterAddress: ", emitterAddress);
Lets walk through each of the arguments of this function and what they mean.
`POLYGON_TOKEN_BRIDGE` is the address of the token bridge module on the Polygon network. You can find it and other addresses on the Deployment Info page.
`POLYGON_TOKEN_BRIDGE` is the address of the token bridge module on the Polygon network. You can find it and other addresses on the [contracts](../../reference/contracts.md) page.
`PolygonWallet` is a signer you get from the Ethers library that holds a private key that can sign transactions.