Skip to content

Instantly share code, notes, and snippets.

@hewigovens
Created August 15, 2018 08:34
Show Gist options
  • Save hewigovens/1271eaafca486ded86b5f6e6417c1b5c to your computer and use it in GitHub Desktop.
Save hewigovens/1271eaafca486ded86b5f6e6417c1b5c to your computer and use it in GitHub Desktop.
ethereumjs_abi_test.js
const ethUtil = require('ethereumjs-util');
const abi = require('ethereumjs-abi');
const result = abi.rawEncode(['bytes32'], ['bBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB'])
console.log(ethUtil.bufferToHex(result));
//0x6242624242424262624242426262624262624262626262424262426262626242
@hewigovens
Copy link
Author

ABIEncoder.swift

func testEncodeBytesData() {
    let result = "6242624242424262624242426262624262624262626262424262426262626242"
    let encoder = ABIEncoder()
    let string = "bBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
    let data = Data(bytes: Array(string.utf8))
    try! encoder.encode(ABIValue(data, type: .bytes(32)))
    XCTAssertEqual(encoder.data.hexString, result)
    //0x62426242424242626242424262626242626242626262624242624262626262426242626242426242000000000000000000000000000000000000000000000000
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment