forked from anchorpw/ethereum-kit-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# ERC20 Token | ||
|
||
## Transfer | ||
|
||
* Create an instance of an ERC20 token | ||
|
||
```swift | ||
let erc20Token = ERC20(contractAddress: "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07", decimal: 18, symbol: "OMG") | ||
``` | ||
|
||
* Create a data parameter which will be sent with `RawTransaction` data section | ||
|
||
**Put contract address to `RawTransaction` `to` parameter** | ||
|
||
```swift | ||
let parameterData: Data | ||
do { | ||
parameterData = try erc20Token.generateDataParameter(toAddress: "0x88b44BC83add758A3642130619D61682282850Df", amount: "100") | ||
} catch let error { | ||
fatalError("Error: \(error.localizedDescription)") | ||
} | ||
|
||
let rawTransaction = RawTransaction( | ||
wei: "0", | ||
to: erc20Token.contractAddress, | ||
gasPrice: Converter.toWei(GWei: 10), | ||
gasLimit: 21000, | ||
nonce: 10, | ||
data: parameterData | ||
) | ||
``` | ||
|
||
* Sign tx and send a parameter data with `sendRawTransaction` RPC | ||
|
||
```swift | ||
|
||
let tx: String | ||
do { | ||
tx = try wallet.sign(rawTransaction: rawTransaction) | ||
} catch let error { | ||
fatalError("Error: \(error.localizedDescription)") | ||
} | ||
|
||
geth.sendRawTransaction(rawTransaction: tx) { result in | ||
// do something with response | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters